Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int a[1001], b[1001], startingPosition, s, n;
  5. bool solutionExists = 0, isGood;
  6.  
  7. int main()
  8. {
  9. cin >> n;
  10. for (int i = 0; i < n; ++i)
  11. {
  12. cin >> a[i] >> b[i];
  13. }
  14. for (int i = 0; i < n; ++i)
  15. {
  16. isGood = 1;
  17. s = 0;
  18. for (int j = i; j < n + i; ++j)
  19. {
  20. s += b[j % n] - a[j % n];
  21. if (s < 0) isGood = 0;
  22. }
  23. if (isGood) { solutionExists = 1; startingPosition = i; break; }
  24. }
  25. if (!solutionExists) cout << -1;
  26. else cout << startingPosition + 1;
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement