제출 #1016475

#제출 시각아이디문제언어결과실행 시간메모리
1016475yanbGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<long long, long long> #define t3i tuple<long long, long long, long long> signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); 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<int> pos(n), neg(n); for (int i = 0; i < n - 1; i++) pos[i + 1] = pos[i] + max(0ll, 1 - d[i]); for (int i = n - 2; i >= 0; i--) neg[i] = neg[i + 1] + max(0ll, d[i] + 1); /*for (int i = 0; i < n - 1; i++) cout << d[i] << "\t"; cout << "\n"; for (int i = 0; i < n; i++) cout << pos[i] << "\t"; cout << "\n"; for (int i = 0; i < n; i++) cout << neg[i] << "\t"; cout << "\n";*/ int ans = 1e11; for (int i = 0; i < n - 1; i++) ans = min(ans, max(pos[i], neg[i])); cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...