# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1159066 | egregious | Safety (NOI18_safety) | C++20 | 137 ms | 12604 KiB |
// https://oj.uz/problem/view/NOI18_safety
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
int n; ll k, dl = 0, dr = 0, mn = 0;
cin >> n >> k;
// {l} + dl and {r} + dr store points at which slope changes
multiset<ll> l, r;
for (int i = 0; i < n; i++) {
ll s; cin >> s;
if (l.size() && s < *l.rbegin() + dl) {
l.insert({s - dl, s - dl}); // insert value twice
r.insert(*l.rbegin() + dl - dr);
int x = *++l.rbegin();
mn += *l.rbegin() - x + abs(x + dl - s);
l.erase(*l.rbegin());
}
else if (r.size() && s > *r.begin() + dr) {
r.insert({s - dr, s - dr}); // insert value twice
l.insert(*r.begin() + dr - dl);
int x = *++r.begin();
mn += x - *r.begin() + abs(x + dr - s);
r.erase(*r.begin());
}
else l.insert(s - dl), r.insert(s - dr);
dl -= k, dr += k;
}
cout << mn << endl;
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |