제출 #529498

#제출 시각아이디문제언어결과실행 시간메모리
529498abc864197532Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
28 ms6984 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define pb push_back #define eb emplace_back #define pii pair<int,int> #define X first #define Y second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #ifdef Doludu #define test(x...) abc("[" + string(#x) + "]", x) #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #else #define test(x...) void(0) #define owo ios::sync_with_stdio(false), cin.tie(0) #endif const int N = 200000; int main () { owo; int n; cin >> n; vector <int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; vector <int> d(n - 1); for (int i = 0; i < n - 1; ++i) d[i] = a[i + 1] - a[i]; vector <lli> pre(n), suf(n); for (int i = 1; i < n; ++i) { pre[i] = pre[i - 1] + (d[i - 1] <= 0 ? -d[i - 1] + 1 : 0); } for (int i = n - 2; ~i; --i) { suf[i] = suf[i + 1] + (d[i] >= 0 ? d[i] + 1 : 0); } lli ans = 1ll << 60; for (int i = 0; i < n; ++i) ans = min(ans, max(pre[i], suf[i])); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...