# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90286 | mirbek01 | Mountain Trek Route (IZhO12_route) | C++17 | 2 ms | 612 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
int n, k, a[N];
int main(){
scanf("%d %d", &n, &k);
for(int i = 1; i <= n; i ++){
scanf("%d", a + i);
}
int lo = 1, hi = 1e9, m;
while(lo <= hi){
int md = (lo + hi) >> 1;
long long cnt = 0;
for(int i = 1; i <= n; i ++){
if(a[i] < md)
cnt += md - a[i];
}
if(cnt <= k)
lo = md + 1, m = md;
else
hi = md - 1;
}
long long bg = 0, cur = 0;
for(int i = 1; i <= n; i ++){
int nxt = i + 1;
if(nxt > n)
nxt = 1;
bg += abs(a[i] - a[nxt]);
}
for(int i = 1; i <= n; i ++)
a[i] = max(a[i], m);
for(int i = 1; i <= n; i ++){
int nxt = i + 1;
if(nxt > n)
nxt = 1;
cur += abs(a[i] - a[nxt]);
}
cout << bg - cur << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |