이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
multiset<int> local_minimum(multiset<int> s, int h) {
assert((int) s.size() % 2 == 0);
multiset<int> s2;
int slope = -(int) s.size() / 2;
for (auto &x : s) {
if (slope < 0) {
s2.insert(x - h);
}
if (slope >= 0) {
s2.insert(x + h);
}
slope++;
}
return s2;
}
int get(multiset<int> s, int a, int b) {
int n = (int) s.size();
vector<int> xs;
for (auto &it : s) {
xs.push_back(it);
}
for (int i = n - 1; i >= 0; i--) {
b += xs[i];
a--;
if (a == 0) {
return b;
}
}
assert(0);
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
multiset<int> s;
int n, h, x, b = 0;
cin >> n >> h >> x;
s.insert(x);
s.insert(x);
b = -x;
for (int i = 2; i <= n; i++) {
s = local_minimum(s, h);
cin >> x;
b -= (i - 1) * h; /// I have no clue why this happens lol
s.insert(x);
s.insert(x);
auto it = s.end();
it--;
b -= x;
}
cout << get(s, (int) s.size() / 2, b) << "\n";
}
# | 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... |