代码
#include <iostream>
#include <map>
using namespace std;
int main() {
int n;
cin>>n;
map<int, int> m;
int maxPos = -1;
int max = 0;
for(int i=0; i<n; i++){
int tmpPos, tmpScore;
cin>>tmpPos>>tmpScore;
if(m[tmpPos]==0){
m[tmpPos] = tmpScore;
}
else{
m[tmpPos] += tmpScore;
}
if(m[tmpPos]>max){
max = m[tmpPos];
maxPos = tmpPos;
}
}
cout<<maxPos<<" "<<max<<endl;
return 0;
}
注解
1、map的使用:
定义:
#include <map>
map<int, int> m;
查找:
if(m[tmpPos]==0){
m[tmpPos] = tmpScore;
}
else{
m[tmpPos] += tmpScore;
}