Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int a[1001], b[1001], startingPosition, s, n;
- bool solutionExists = 0, isGood;
- int main()
- {
- cin >> n;
- for (int i = 0; i < n; ++i)
- {
- cin >> a[i] >> b[i];
- }
- for (int i = 0; i < n; ++i)
- {
- isGood = 1;
- s = 0;
- for (int j = i; j < n + i; ++j)
- {
- s += b[j % n] - a[j % n];
- if (s < 0) isGood = 0;
- }
- if (isGood) { solutionExists = 1; startingPosition = i; break; }
- }
- if (!solutionExists) cout << -1;
- else cout << startingPosition + 1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement