Guest User

Untitled

a guest
Aug 9th, 2015
170
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #include <assert.h>
  3. #include <unordered_map>
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. typedef long double ld;
  8. typedef vector < long long > vll;
  9. typedef pair < long long, long long > pll;
  10. typedef pair < int, int > pii;
  11. typedef vector < int > vii;
  12.  
  13. #define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
  14. #define l(x) (((x) << 1) | 1)
  15. #define r(x) ((l(x)) + 1)
  16. #define mp make_pair
  17. #define fst first
  18. #define snd second
  19.  
  20. ll t, n, u, v, m, q, r, ql, qr, k, l, s, x, y, w;
  21. const int N = 1e5 + 500;
  22. const long long mod = 1e9 + 7;
  23. const long long INF = 1LL << 57LL;
  24. const bool JUDGE = false;
  25.  
  26. int main(){
  27.     csl;
  28.     if (JUDGE) {
  29.         freopen("in.txt", "r", stdin);
  30.         freopen("out.txt", "w", stdout);
  31.     }
  32.     cin >> n;
  33.     ll next;
  34.     ll prev = - INF;
  35.     ll cura = -INF;
  36.     ll curb = INF;
  37.     ll ans = INF;
  38.     for (int i = 0; i < n; ++i) {
  39.         cin >> next;
  40.         curb = min(curb, next);
  41.         if (next < prev) ans = 0;
  42.         ll tempa, tempb;
  43.         tempa = 2 * next - curb;
  44.         tempb = 2 * next - cura;
  45.         cura = tempa;
  46.         curb = tempb;
  47.         if (cura > curb) ans = 0;
  48.         prev = next;
  49.     }
  50.     if (ans) cout << curb - cura + 1 << '\n';
  51.     else cout << ans << '\n';
  52.     return 0;
  53. }
RAW Paste Data