1 条题解

  • 0
    @ 2026-8-29 11:31:35
    #include <bits/stdc++.h>
    using namespace std;
    
    struct k {
    	int a = 0, b = 0, c = 0, d = 0, sum = 0;
    	string name;
    } h[1005];
    int n, m;
    
    bool cmp(k x, k y) {
    	if (x.sum != y.sum)
    		return x.sum > y.sum;
    	if(x.sum==y.sum)
        return x.name<y.name;
    }
    
    int main() {
    	freopen("top.in", "r", stdin);
    	freopen("top.out", "w", stdout);
    	cin >> n >> m;
    	for (int i = 1; i <= n; i++)
    		cin >> h[i].name;
    	for (int i = 1; i <= m; i++) {
    		int typ;
    		cin >> typ;
    		if (typ == 1) {
    			int k, l, p;
    			string s;
    			cin >> s >> k >> l;
    			for (int j = 1; j <= n; j++) {
    				if (s == h[j].name) {
    					p = j;
    					break;
    				}
    			}
    			if (k == 1) {
    				h[p].a = l;
    			}
    			if (k == 2)
    				h[p].b = l;
    			if (k == 3)
    				h[p].c = l;
    			if (k == 4)
    				h[p].d = l;
    			h[p].sum = h[p].a + h[p].b + h[p].c + h[p].d;
    		} else if (typ == 2) {
    			sort(h + 1, h + 1 + n, cmp);
    			cout << h[1].name << endl;
    		}
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    4505
    时间
    1000ms
    内存
    512MiB
    难度
    4
    标签
    (无)
    递交数
    75
    已通过
    33
    上传者