# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
226591 |
2020-04-24T13:03:37 Z |
bortoz |
Feast (NOI19_feast) |
C++17 |
|
117 ms |
27112 KB |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pc __builtin_popcount
constexpr int MAXN = 1 << 17;
int main() {
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
map<int, ll> S;
ll sum = 0;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
if (a == 0 || (sum == 0 && a < 0)) continue;
if ((a >= 0) == (sum >= 0)) {
sum += a;
} else {
S.emplace(i, sum);
sum = a;
}
}
if (sum > 0) S.emplace(N, sum);
priority_queue<pair<ll, int>> Q;
for (auto [i, x] : S) {
Q.emplace(-abs(x), i);
}
while (S.size() > 2 * K) {
auto [_, i] = Q.top();
Q.pop();
auto it = S.find(i);
if (it == S.begin()) {
S.erase(next(it));
S.erase(it);
} else if (next(it) == S.end()) {
S.erase(prev(it));
S.erase(it);
} else {
auto pv = prev(it), nx = next(it);
it->se += pv->se + nx->se;
S.erase(pv);
S.erase(nx);
Q.emplace(-abs(it->se), it->fi);
}
}
ll res = 0;
for (auto [_, x] : S) {
res += max(x, 0ll);
}
cout << res << endl;
return 0;
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:36:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (S.size() > 2 * K) {
~~~~~~~~~^~~~~~~
feast.cpp:37:15: warning: unused variable '_' [-Wunused-variable]
auto [_, i] = Q.top();
^
feast.cpp:56:18: warning: unused variable '_' [-Wunused-variable]
for (auto [_, x] : S) {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
3320 KB |
Output is correct |
2 |
Correct |
50 ms |
3192 KB |
Output is correct |
3 |
Correct |
51 ms |
3192 KB |
Output is correct |
4 |
Correct |
50 ms |
3192 KB |
Output is correct |
5 |
Correct |
48 ms |
3192 KB |
Output is correct |
6 |
Correct |
47 ms |
3196 KB |
Output is correct |
7 |
Correct |
51 ms |
3192 KB |
Output is correct |
8 |
Correct |
55 ms |
3320 KB |
Output is correct |
9 |
Correct |
52 ms |
3192 KB |
Output is correct |
10 |
Correct |
48 ms |
3192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
1408 KB |
Output is correct |
2 |
Correct |
30 ms |
1536 KB |
Output is correct |
3 |
Correct |
31 ms |
1408 KB |
Output is correct |
4 |
Correct |
30 ms |
1536 KB |
Output is correct |
5 |
Correct |
50 ms |
3192 KB |
Output is correct |
6 |
Correct |
28 ms |
1408 KB |
Output is correct |
7 |
Correct |
31 ms |
1536 KB |
Output is correct |
8 |
Correct |
50 ms |
3196 KB |
Output is correct |
9 |
Correct |
50 ms |
3200 KB |
Output is correct |
10 |
Correct |
30 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
117 ms |
27112 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
3320 KB |
Output is correct |
2 |
Correct |
50 ms |
3192 KB |
Output is correct |
3 |
Correct |
51 ms |
3192 KB |
Output is correct |
4 |
Correct |
50 ms |
3192 KB |
Output is correct |
5 |
Correct |
48 ms |
3192 KB |
Output is correct |
6 |
Correct |
47 ms |
3196 KB |
Output is correct |
7 |
Correct |
51 ms |
3192 KB |
Output is correct |
8 |
Correct |
55 ms |
3320 KB |
Output is correct |
9 |
Correct |
52 ms |
3192 KB |
Output is correct |
10 |
Correct |
48 ms |
3192 KB |
Output is correct |
11 |
Correct |
29 ms |
1408 KB |
Output is correct |
12 |
Correct |
30 ms |
1536 KB |
Output is correct |
13 |
Correct |
31 ms |
1408 KB |
Output is correct |
14 |
Correct |
30 ms |
1536 KB |
Output is correct |
15 |
Correct |
50 ms |
3192 KB |
Output is correct |
16 |
Correct |
28 ms |
1408 KB |
Output is correct |
17 |
Correct |
31 ms |
1536 KB |
Output is correct |
18 |
Correct |
50 ms |
3196 KB |
Output is correct |
19 |
Correct |
50 ms |
3200 KB |
Output is correct |
20 |
Correct |
30 ms |
1528 KB |
Output is correct |
21 |
Runtime error |
117 ms |
27112 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |