# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1081638 | coolboy19521 | Mountain Trek Route (IZhO12_route) | C++17 | 1 ms | 348 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"
#define ll long long
using namespace std;
const int sz = 1e6 + 6;
int a[sz];
int main() {
int n, k; cin >> n >> k;
for (int i = 0; i < n; i ++)
cin >> a[i];
int pr = 0;
for (int i = 0; i < n; i ++) {
int j = (i - 1 + n) % n;
pr += abs(a[i] - a[j]);
}
int lo = *min_element(a, a + n), hi = *max_element(a, a + n);
while (lo != hi) {
int mi = (lo + hi + 1) / 2;
int r = 0;
for (int i = 0; i < n; i ++)
r += max(mi - a[i], 0);
if (r <= k) lo = mi;
else hi = mi - 1;
}
for (int i = 0; i < n; i ++)
a[i] = max(a[i], lo);
int r = 0;
for (int i = 0; i < n; i ++) {
int j = (i - 1 + n) % n;
r += abs(a[i] - a[j]);
}
cout << pr - r << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |