Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<cstring>
- #include<vector>
- #include<algorithm>
- #define f first
- #define s second
- #define PRIM 23
- using namespace std;
- vector<pair<int,int> > points[1002]; ///pair<punctaj_curent, step>
- int i, j, n, len, val, mx, sol, best;
- char rez[35][1002], s[35];
- bool ok;
- int lastpoz(int poz){
- vector<pair<int,int> >::iterator it;
- int sum=0;
- for (it=points[poz].begin();it!=points[poz].end();++it) {
- sum+=(*it).f;
- if (sum>=mx) return (*it).s;
- }
- return 999999999;
- }
- int main(){
- //freopen("in.txt","r",stdin);
- //freopen("out.txt","w",stdout);
- scanf("%d\n", &n);
- len=0; mx=0;
- for (i=1;i<=n;++i) {
- scanf("%s %d\n", s, &val);
- ok=true;
- for (j=1;j<=len;++j) {
- if (strcmp(s, rez[j])==0) {
- points[j].push_back(make_pair((points[j].back()).f+val, i));
- ok=false; break;
- }
- }
- if (ok) {
- strcpy(rez[++len], s);
- points[len].push_back(make_pair(val, i));
- }
- }
- for (i=1;i<=len;i++) {
- if ((points[i].back()).f>mx) {
- mx=(points[i].back()).f; sol=i; best=lastpoz(i);
- }
- else if (((points[i].back()).f==mx)&&(lastpoz(i)<best)) {
- mx=(points[i].back()).f; sol=i; best=lastpoz(i);
- }
- }
- printf("%s\n", rez[sol]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement