제출 #653992

#제출 시각아이디문제언어결과실행 시간메모리
6539921zaid1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n'; const int M = 1e5+5, MOD = 1e9+7; signed main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; vector<int> v(n); for (int &i:v) cin >> i; vector<int> x; for (int i = 1; i < n; i++) x.push_back(v[i]-v[i-1]); int a = 0, b = 0, ans = INT_MAX; for (int i:x) if (i >= 0) a+=i+1; for (int i = 0; i < n; i++) { if (i) { if (x[i-1] >= 0) a -= x[i-1]+1; if (x[i-1] <= 0) b -= x[i-1]-1; } ans = min(ans, max(a, b)); } cout << ans << endl; return 0; } /* 8 12 2 34 85 4 91 29 85 -11 33 52 -82 88 -63 57 5 9 7 5 3 1 -2 -2 -2 -2 5 3 2 2 3 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...