fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(NULL);
  7. cout.tie(NULL);
  8. int n;
  9. cin>>n;
  10. int a[n<<1],b[n<<1];
  11. long long int w=0;
  12. for(int i=0;i<n;++i)
  13. {
  14. cin>>a[i]>>b[i];
  15. a[n+i]=a[i];b[n+i]=b[i];
  16. }
  17. for(int i=0,j=0;i<n;i=j)
  18. {
  19. w=0;
  20. while((j<(i+n))&&((a[j]+w)>=b[j]))
  21. {
  22. w+=(a[j]-b[j]);
  23. ++j;
  24. }
  25. if(j==(i+n))
  26. {
  27. cout<<(i+1);
  28. return 0;
  29. }
  30. ++j;
  31. }
  32. cout<<"0";
  33. return 0;
  34. }
Success #stdin #stdout 0s 4316KB
stdin
3
6 4
3 7
4 3
stdout
Standard output is empty