SHARE
TWEET

Untitled

a guest Dec 10th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top