Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.    int g,l,maxx=0,now=-5; //maxx fih l position mta3 l frog lawel. now fih l frog lawel bch ken ma5lat 3lih 7ata 7ad nzidah +1 tour  
  5.    cin>>g>>l;
  6.    map<int,int>mapp; // mapp hedhi feha kol frog wl position mta3ah
  7.    map<int,int>score; // mapp hedhi feha kol frog w guedech mn tour fl sadara
  8.     for(int i=1;i<=g;i++){
  9.       mapp[i]=0;
  10.       score[i]=0;
  11.     } // mena 3amart l maps mta3i bl frogs
  12.     for(int i=0;i<l-1;i++){
  13.       int x,y;//x: frog num,,,, y: saut distance
  14.       cin>>x>>y;
  15.       mapp[x]+=y;
  16.       if(mapp[x]==maxx) continue;      
  17.       else if(mapp[x]>maxx){
  18.          score[x]++;
  19.          maxx=mapp[x];
  20.          now=x;
  21.       }
  22.       else if(now!=-5){
  23.          score[now]++;
  24.       }
  25.     }
  26.     int maxis=0; // maxis bch nchouf chkoun 3ndah akther score or chkoun 3ada akther atra7 lawel
  27.     for(int i=1;i<=g;i++){
  28.       maxis=max(score[i],maxis);
  29.     }
  30.     for(int i=1;i<=g;i++){
  31.       if(score[i]==maxis){
  32.          cout<<i;
  33.          break;
  34.       }
  35.     }
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement