Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <assert.h>
- #include <unordered_map>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef vector < long long > vll;
- typedef pair < long long, long long > pll;
- typedef pair < int, int > pii;
- typedef vector < int > vii;
- #define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
- #define l(x) (((x) << 1) | 1)
- #define r(x) ((l(x)) + 1)
- #define mp make_pair
- #define fst first
- #define snd second
- ll t, n, u, v, m, q, r, ql, qr, k, l, s, x, y, w;
- const int N = 1e5 + 500;
- const long long mod = 1e9 + 7;
- const long long INF = 1LL << 57LL;
- const bool JUDGE = false;
- int main(){
- csl;
- if (JUDGE) {
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- }
- cin >> n;
- ll next;
- ll prev = - INF;
- ll cura = -INF;
- ll curb = INF;
- ll ans = INF;
- for (int i = 0; i < n; ++i) {
- cin >> next;
- curb = min(curb, next);
- if (next < prev) ans = 0;
- ll tempa, tempb;
- tempa = 2 * next - curb;
- tempb = 2 * next - cura;
- cura = tempa;
- curb = tempb;
- if (cura > curb) ans = 0;
- prev = next;
- }
- if (ans) cout << curb - cura + 1 << '\n';
- else cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement