#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
multiset<int> form(multiset<int> s1, multiset<int> s2, int add1, int add2) {
multiset<int> s;
for (auto &x : s1) {
s.insert(x + add1);
}
for (auto &x : s2) {
s.insert(x + add2);
}
return s;
}
void print(multiset<int> s) {
cout << " : ";
for (auto &x : s) {
cout << x << " ";
}
cout << "\n";
}
int get(multiset<int> s, int a, unsigned long long 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> s1, s2;
int n, h, x, add1 = 0, add2 = 0;
unsigned long long b = 0;
cin >> n >> h >> x;
s1.insert(x);
s2.insert(x);
b = -x;
for (int i = 2; i <= n; i++) {
b -= (i - 1) * h;
add1 -= h;
add2 += h;
int cut = *s2.begin() + add2;
int x;
cin >> x;
b -= x;
if (x < cut) {
s1.insert(x - add1);
s1.insert(x - add1);
auto it = s1.end();
it--;
int val = *it + add1;
s1.erase(it);
s2.insert(val - add2);
} else {
s2.insert(x - add2);
s2.insert(x - add2);
auto it = s2.begin();
int val = *it + add2;
s2.erase(it);
s1.insert(val - add1);
}
}
multiset<int> s = form(s1, s2, add1, add2);
cout << get(s, (int) s.size() / 2, b) << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
278 ms |
41564 KB |
Output is correct |
2 |
Correct |
413 ms |
57312 KB |
Output is correct |
3 |
Correct |
432 ms |
59484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
6 ms |
1900 KB |
Output is correct |
29 |
Correct |
6 ms |
1772 KB |
Output is correct |
30 |
Correct |
6 ms |
2044 KB |
Output is correct |
31 |
Correct |
5 ms |
1644 KB |
Output is correct |
32 |
Correct |
5 ms |
1644 KB |
Output is correct |
33 |
Correct |
7 ms |
1900 KB |
Output is correct |
34 |
Correct |
6 ms |
1900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 ms |
492 KB |
Output is correct |
34 |
Correct |
6 ms |
1900 KB |
Output is correct |
35 |
Correct |
6 ms |
1772 KB |
Output is correct |
36 |
Correct |
6 ms |
2044 KB |
Output is correct |
37 |
Correct |
5 ms |
1644 KB |
Output is correct |
38 |
Correct |
5 ms |
1644 KB |
Output is correct |
39 |
Correct |
7 ms |
1900 KB |
Output is correct |
40 |
Correct |
6 ms |
1900 KB |
Output is correct |
41 |
Correct |
7 ms |
1900 KB |
Output is correct |
42 |
Correct |
5 ms |
1516 KB |
Output is correct |
43 |
Correct |
6 ms |
1900 KB |
Output is correct |
44 |
Correct |
6 ms |
1900 KB |
Output is correct |
45 |
Correct |
5 ms |
1772 KB |
Output is correct |
46 |
Correct |
5 ms |
1644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
278 ms |
41564 KB |
Output is correct |
20 |
Correct |
413 ms |
57312 KB |
Output is correct |
21 |
Correct |
432 ms |
59484 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 ms |
492 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
6 ms |
1900 KB |
Output is correct |
38 |
Correct |
6 ms |
1772 KB |
Output is correct |
39 |
Correct |
6 ms |
2044 KB |
Output is correct |
40 |
Correct |
5 ms |
1644 KB |
Output is correct |
41 |
Correct |
5 ms |
1644 KB |
Output is correct |
42 |
Correct |
7 ms |
1900 KB |
Output is correct |
43 |
Correct |
6 ms |
1900 KB |
Output is correct |
44 |
Correct |
7 ms |
1900 KB |
Output is correct |
45 |
Correct |
5 ms |
1516 KB |
Output is correct |
46 |
Correct |
6 ms |
1900 KB |
Output is correct |
47 |
Correct |
6 ms |
1900 KB |
Output is correct |
48 |
Correct |
5 ms |
1772 KB |
Output is correct |
49 |
Correct |
5 ms |
1644 KB |
Output is correct |
50 |
Correct |
445 ms |
60896 KB |
Output is correct |
51 |
Correct |
352 ms |
51168 KB |
Output is correct |
52 |
Correct |
253 ms |
49372 KB |
Output is correct |
53 |
Correct |
290 ms |
58688 KB |
Output is correct |
54 |
Correct |
275 ms |
60380 KB |
Output is correct |
55 |
Correct |
248 ms |
51812 KB |
Output is correct |
56 |
Correct |
275 ms |
56540 KB |
Output is correct |
57 |
Correct |
252 ms |
52188 KB |
Output is correct |
58 |
Correct |
222 ms |
45532 KB |
Output is correct |
59 |
Correct |
282 ms |
57436 KB |
Output is correct |