题目描述->link
思路
- 用school[maxn]存储对应学校总成绩。
- 比较出最大值,记录学校编号。
代码
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;
const int maxn=100000;
int school[maxn]={0};
int main(){
int n,i,stuId,score;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d%d",&stuId,&score);
school[stuId]+=score;
}
int k=1,max=-1;
for(i=1;i<=n;i++){
if(school[i]>max){
max=school[i];
k=i;
}
}
printf("%d %d\n",k,max);
return 0;
}