Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- const long long INF = 1e18;
- int main() {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- int n; cin >> n;
- // no rounding will be needed since all m[i] are even
- long long minX = -INF, maxX = INF;
- long long a = 0; // a +/- x, where x is the first element
- for (int i = 0; i < n; ++i) { // s[i+1]
- long long m; cin >> m; m = 2*m; // convert from mean to sum
- long long b = m - a;
- if (i & 1) minX = max(minX, (a-b)/2); // b + x >= a - x, so x >= (a-b)/2
- else maxX = min(maxX, (b-a)/2); // b - x >= a + x, so x <= (b-a)/2
- a = b;
- }
- cout << max(maxX-minX+1, 0LL) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement