构造的样例都过了
具体思路是用一个 map 记录总分,用一个 map 记录一个人总分到达一定值时所用的时间,当总分 map 中出现不止一个最大值时,则输出分数到达最大值时时间最少的。
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int read(){
int s=0,w=1;
char ch=getchar();
while(ch>'9'||ch<'0'){
if(ch=='-')
w=-w;
ch=getchar();
}
while('0'<=ch&&ch<='9'){
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
void write(int x){
if(x>9)
write(x/10);
putchar(x%10+'0');
}
map<string,int>mark;
map<pair<string,int>,int>times;
string name[1005];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n=read();
int tot=0;
for(int i=1;i<=n;i++){
string op;
int m;
cin>>op;
if(!mark.count(op))
name[++tot]=op;
cin>>m;
mark[op]+=m;
times[make_pair(op,mark[op])]=i;
}
int maxn=-1;
int cnt=0;
string pos[1005];
for(int i=1;i<=tot;i++)
maxn=max(maxn,mark[name[i]]);
for(int i=1;i<=tot;i++)
if(mark[name[i]]==maxn)
cnt++,pos[cnt]=name[i];
if(cnt==1)
cout<<pos[1]<<endl;
else{
int minn=0x7ffffff;
string mpos;
for(int i=1;i<=cnt;i++)
if(times[make_pair(pos[i],mark[pos[i]])]<minn)
minn=times[make_pair(pos[i],mark[pos[i]])],mpos=pos[i];
cout<<mpos<<endl;
}
return 0;
}