fork(2) download
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int t, p1[1000], p2[1000],dif2,dif1,i;
  9. cin>>t;
  10. vector<int> v2;
  11. vector<int> v1;
  12. for(i=0;i<t;i++)
  13. {
  14. cin>>p1[i]>>p2[i];
  15. }
  16.  
  17. for(i=1;i<t;i++)
  18. {
  19. p1[i]+=p1[i-1];
  20. p2[i]+=p2[i-1];
  21. }
  22.  
  23. for(i=0;i<t;i++)
  24. {
  25. int dif1=p1[i]-p2[i];
  26. if(dif1>=0)
  27. v1.push_back(dif1);
  28. int dif2=p2[i]-p1[i];
  29. if(dif2>=0)
  30. v2.push_back(dif2);
  31. }
  32.  
  33. int max1=*max_element(v1.begin(),v1.end());
  34. int max2=*max_element(v2.begin(),v2.end());
  35. //cout<<max1<<" "<<max2<<endl;
  36. if(max1>max2)
  37. cout<<"1"<<" "<<max1;
  38. else
  39. cout<<"2"<<" "<<max2;
  40. }
Success #stdin #stdout 0s 4176KB
stdin
3

20 100

20 100

1000 0
stdout
1 840