Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int MAX = 200005;
- int a[MAX];
- int main() {
- cin.tie(0)->sync_with_stdio(0);
- int b, l;
- cin >> b >> l;
- int v = 0;
- for (int i = 1; i <= l; ++i) {
- cin >> a[i];
- if (i & 1) {
- v += a[i];
- if (v >= b+1) v -= b+1;
- } else {
- v -= a[i];
- if (v < 0) v += b+1;
- }
- }
- if (v == 0) {
- cout << "0 0\n";
- exit(0);
- }
- for (int i = 1; i <= l; ++i) {
- if (i & 1) {
- v -= a[i];
- if (v < 0) v += b+1;
- int rem = b+1-v;
- if (rem == b+1) rem = 0;
- if (rem < a[i]) {
- cout << i << ' ' << rem << '\n';
- exit(0);
- }
- v += a[i];
- if (v >= b+1) v -= b+1;
- } else {
- v += a[i];
- if (v >= b+1) v -= b+1;
- // cout << "Teste 2: " << v << ' ' << a[i] << '\n';
- if (v < a[i]) {
- cout << i << ' ' << v << '\n';
- exit(0);
- }
- v -= a[i];
- if (v < 0) v += b+1;
- }
- }
- cout << "-1 -1\n";
- }
Add Comment
Please, Sign In to add comment