Advertisement
fireLUFFY

TLGCodechef

Jul 17th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define inf 2e18
  6. int MOD=1000000007;//998244353;
  7. const int nn=1000050;
  8. bool prime[nn]; //array to store precalculated primes till 10^6
  9. void cal_primes(){memset(prime,true,sizeof(prime)); for(int i=2;i<=sqrt(nn);++i){ if(prime[i]==true){ for(int j=i*i;j<=nn;j+=i){prime[j]=false;}}}}
  10.  
  11. void solve(int t)
  12. {
  13.     int testcases=t;
  14.     while(t--)
  15.     {
  16.     //  cout<<"Case #"<<(testcases-t)<<": "<<endl;
  17.         int n;cin>>n;
  18.         int x,y;
  19.         vector<pair<int,int>>v;
  20.         for(int i=0;i<n;i++)
  21.         {
  22.             cin>>x>>y;
  23.             v.push_back(make_pair(x,y));
  24.         }
  25.         int lead1=0,lead2=0,score1=0,score2=0;
  26.         for(int i=0;i<n;i++)
  27.         {
  28.             score1+=v[i].first; score2+=v[i].second;
  29.             if(score1>score2)
  30.                 lead1=max(lead1,score1-score2);
  31.             else
  32.                 lead2=max(lead2,score2-score1);
  33.         }
  34.         if(lead2>lead1)
  35.             cout<<2<<" "<<lead2;
  36.         else
  37.             cout<<1<<" "<<lead1;
  38.     }
  39. }
  40.  
  41. main()
  42. {
  43.     auto start=chrono::system_clock::now();
  44.     {
  45.         #ifndef ONLINE_JUDGE
  46.             freopen("input.txt","r",stdin);
  47.             freopen("output.txt","w",stdout);
  48.             freopen("error.txt","w",stderr);
  49.         #endif 
  50.         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  51.         int t=1;
  52.     //  cin>>t;
  53.         solve(t);
  54.     }
  55.     auto end=chrono::system_clock::now();
  56.     chrono::duration<double> elapsed=end-start;
  57.     //cout<<endl<<"Time taken: "<<elapsed.count()<<" sec";
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement