1030我得好好想想,老是超时,一会儿再放
水题不多说
C/C++
1 #include <iostream> 2 #include <vector> 3 using namespace std; 4 5 int main() { 6 int n = 0, id = 0, gra = 0, max = 0; 7 cin >> n; 8 vector<int> all(n + 1); //C的话就用足够大的数组进行存储 9 for (int i = 0; i < n; i++) { 10 cin >> id >> gra; 11 all[id] += gra; 12 } 13 for (int i = 0; i < n + 1; i++) { //注意是n+1,因为编号并不是从零开始计数的,写n测试点3会错误 14 if (all[i] > max) { 15 max = all[i]; 16 id = i; 17 } 18 } 19 cout << id << " " << max; 20 return 0; 21 }