# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
634052 |
2022-08-23T18:07:05 Z |
izanbf |
Hacker (BOI15_hac) |
C++14 |
|
293 ms |
16088 KB |
#include <bits/stdc++.h>
using namespace std;
#define D(x) cerr << #x << " = " << x << ", "
using vi = vector<int>;
using vvi = vector<vi>;
vi compute_ksums(const vi& a, int k) {
int n = a.size();
vi v(2*n);
for (int i = 0; i < n; ++i) {
v[i] = v[n+i] = a[i];
}
vi pre(2*n+1); // pre[i+1] = v[0]+...+v[i]
for (int i = 0; i < 2*n; ++i) {
pre[i+1] = pre[i] + v[i];
}
vi ksums(n); // ksums[i] = v[i] + ... + v[i+k-1]
for (int i = 0; i < n; ++i) {
ksums[i] = pre[i+k] - pre[i];
}
return ksums;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
int k = n/2; // range of the deffender
int sum = 0;
vi v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
sum += v[i];
}
vi ksums = compute_ksums(v, k);
multiset<int> s;
int l = 1;
int r = n-k;
int ans = 0;
for (int i = l; i <= r; ++i) {
s.insert(-ksums[i]);
}
for (int i = 0; i < n; ++i) {
int best = -(*s.begin());
ans = max(ans, sum-best);
r = (r+1)%n;
s.insert(-ksums[r]);
s.erase(s.find(-ksums[l]));
l = (l+1)%n;
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
28 ms |
2796 KB |
Output is correct |
5 |
Correct |
108 ms |
6584 KB |
Output is correct |
6 |
Correct |
157 ms |
8152 KB |
Output is correct |
7 |
Correct |
141 ms |
9596 KB |
Output is correct |
8 |
Correct |
293 ms |
15944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
2 ms |
468 KB |
Output is correct |
35 |
Correct |
28 ms |
2796 KB |
Output is correct |
36 |
Correct |
108 ms |
6584 KB |
Output is correct |
37 |
Correct |
157 ms |
8152 KB |
Output is correct |
38 |
Correct |
141 ms |
9596 KB |
Output is correct |
39 |
Correct |
293 ms |
15944 KB |
Output is correct |
40 |
Correct |
4 ms |
596 KB |
Output is correct |
41 |
Correct |
8 ms |
916 KB |
Output is correct |
42 |
Correct |
11 ms |
1272 KB |
Output is correct |
43 |
Correct |
92 ms |
6580 KB |
Output is correct |
44 |
Correct |
286 ms |
15976 KB |
Output is correct |
45 |
Correct |
43 ms |
3380 KB |
Output is correct |
46 |
Correct |
151 ms |
9592 KB |
Output is correct |
47 |
Correct |
283 ms |
16088 KB |
Output is correct |
48 |
Correct |
227 ms |
15976 KB |
Output is correct |
49 |
Correct |
207 ms |
15976 KB |
Output is correct |
50 |
Correct |
198 ms |
15980 KB |
Output is correct |