This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Autor: Bartłomiej Czarkowski
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif
const int N = 201000;
int n;
long long t[N];
long long pref_nad[N];
long long suff_nad[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &t[i]);
}
for (int i = 2; i <= n; ++i) {
pref_nad[i] = pref_nad[i - 1];
if (t[i] <= t[i - 1]) {
pref_nad[i] += t[i - 1] - t[i] + 1;
}
}
for (int i = n - 1; i; --i) {
suff_nad[i] = suff_nad[i + 1];
if (t[i] <= t[i + 1]) {
suff_nad[i] += t[i + 1] - t[i] + 1;
}
}
long long odp = 1e18;
for (int i = 1; i <= n; ++i) {
//~ debug(i, pref_nad[i], suff_nad[i]);
odp = min(odp, max(pref_nad[i], suff_nad[i]));
}
printf("%lld\n", odp);
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%lld", &t[i]);
| ~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |