Record the position of the maximum value and use the array subscript as the class number.
#include <iostream> using namespace std; intmain() { int n; cin >> n; int a[100001] = {0}; int max = 0; for(int i = 0; i < n; i++) { int num, grade; cin >> num >> grade; a[num] += grid; if(a[max] < a[num]) { max = num; } } cout << max << " " << a[max]; return 0; }