a53

Excursie

a53
May 18th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. cin>>n;
  8. int A[n],B[n];
  9. for(int i=0;i<n;++i)
  10. cin>>A[i]>>B[i];
  11. int en,ea,nro,j;
  12. for(int i=0;i<n;++i)
  13. {
  14. j=i;
  15. en=A[j];
  16. ea=B[j];
  17. nro=0;
  18. while(ea>=en&&nro<n)
  19. ea-=en,++j,j%=n,ea+=B[j],en=A[j],++nro;
  20. if(nro==n)
  21. {
  22. cout<<i+1;
  23. return 0;
  24. }
  25. }
  26. cout<<-1;
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment