danielvitor23

Creating Multiples

Nov 1st, 2021 (edited)
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MAX = 200005;
  5.  
  6. int a[MAX];
  7.  
  8. int main() {
  9.   cin.tie(0)->sync_with_stdio(0);
  10.  
  11.   int b, l;
  12.   cin >> b >> l;
  13.  
  14.   int v = 0;
  15.   for (int i = 1; i <= l; ++i) {
  16.     cin >> a[i];
  17.     if (i & 1) {
  18.       v += a[i];
  19.       if (v >= b+1) v -= b+1;
  20.     } else {
  21.       v -= a[i];
  22.       if (v < 0) v += b+1;
  23.     }
  24.   }
  25.  
  26.   if (v == 0) {
  27.     cout << "0 0\n";
  28.     exit(0);
  29.   }
  30.  
  31.   for (int i = 1; i <= l; ++i) {
  32.     if (i & 1) {
  33.       v -= a[i];
  34.       if (v < 0) v += b+1;
  35.       int rem = b+1-v;
  36.       if (rem == b+1) rem = 0;
  37.       if (rem < a[i]) {
  38.         cout << i << ' ' << rem << '\n';
  39.         exit(0);
  40.       }
  41.       v += a[i];
  42.       if (v >= b+1) v -= b+1;
  43.     } else {
  44.       v += a[i];
  45.       if (v >= b+1) v -= b+1;
  46.       // cout << "Teste 2: " << v << ' ' << a[i] << '\n';
  47.       if (v < a[i]) {
  48.         cout << i << ' ' << v << '\n';
  49.         exit(0);
  50.       }
  51.       v -= a[i];
  52.       if (v < 0) v += b+1;
  53.     }
  54.   }
  55.  
  56.   cout << "-1 -1\n";
  57. }
Add Comment
Please, Sign In to add comment