1 #include<iostream> 2 3 using namespace std; 4 const int maxn =100010; 5 int school[maxn]={0}; 6 int main() 7 { 8 int n; 9 cin>>n; 10 int schID,score; 11 int maxgrade=-1; 12 int flag=1; 13 for(int i=0;i<n;i++) 14 { 15 cin>>schID>>score; 16 17 school[schID]+=score; 18 19 } for(int j=1;j<=n;j++) 20 { 21 if(maxgrade<school[j]) 22 { 23 maxgrade=school[j]; 24 flag=j; 25 } 26 } 27 cout<<flag<<" "<<maxgrade<<endl; 28 29 return 0; 30 }
参考了《算法笔记》
C++数组初始化
int a[n]={0}; // 注意n必须为const类型,否则错误