# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
647416 |
2022-10-02T13:16:03 Z |
LeonaRaging |
Feast (NOI19_feast) |
C++14 |
|
48 ms |
7752 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define ll long long
#define pb push_back
#define db(val) "[" #val " = " << (val) << "] "
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 4;
const int INF = 1e9;
int n, k, a[maxn];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen(".INP", "r", stdin);
//freopen(".OUT", "w", stdout);
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
priority_queue<int, vector<int>, greater<int>> pq;
int cur = 0, cnt = 0, res = 0;
a[n + 1] = -a[n];
for (int i = 1; i <= n + 1; i++) {
if (a[i] * a[i - 1] < 0) {
if (cur > 0) {
res += cur;
cnt++;
}
pq.push(abs(cur));
cur = 0;
}
cur += a[i];
}
while (cnt > k) {
res -= pq.top(); pq.pop();
cnt--;
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
5324 KB |
Output is correct |
2 |
Correct |
32 ms |
5392 KB |
Output is correct |
3 |
Correct |
30 ms |
5452 KB |
Output is correct |
4 |
Correct |
31 ms |
5420 KB |
Output is correct |
5 |
Correct |
29 ms |
5396 KB |
Output is correct |
6 |
Correct |
32 ms |
5380 KB |
Output is correct |
7 |
Correct |
30 ms |
5364 KB |
Output is correct |
8 |
Correct |
33 ms |
5452 KB |
Output is correct |
9 |
Correct |
34 ms |
5304 KB |
Output is correct |
10 |
Correct |
30 ms |
5324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
3616 KB |
Output is correct |
2 |
Correct |
21 ms |
3716 KB |
Output is correct |
3 |
Correct |
19 ms |
3660 KB |
Output is correct |
4 |
Correct |
25 ms |
3636 KB |
Output is correct |
5 |
Correct |
29 ms |
5296 KB |
Output is correct |
6 |
Correct |
19 ms |
3640 KB |
Output is correct |
7 |
Correct |
20 ms |
3736 KB |
Output is correct |
8 |
Correct |
33 ms |
5448 KB |
Output is correct |
9 |
Correct |
31 ms |
5284 KB |
Output is correct |
10 |
Correct |
19 ms |
3748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
48 ms |
7752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
5324 KB |
Output is correct |
2 |
Correct |
32 ms |
5392 KB |
Output is correct |
3 |
Correct |
30 ms |
5452 KB |
Output is correct |
4 |
Correct |
31 ms |
5420 KB |
Output is correct |
5 |
Correct |
29 ms |
5396 KB |
Output is correct |
6 |
Correct |
32 ms |
5380 KB |
Output is correct |
7 |
Correct |
30 ms |
5364 KB |
Output is correct |
8 |
Correct |
33 ms |
5452 KB |
Output is correct |
9 |
Correct |
34 ms |
5304 KB |
Output is correct |
10 |
Correct |
30 ms |
5324 KB |
Output is correct |
11 |
Correct |
22 ms |
3616 KB |
Output is correct |
12 |
Correct |
21 ms |
3716 KB |
Output is correct |
13 |
Correct |
19 ms |
3660 KB |
Output is correct |
14 |
Correct |
25 ms |
3636 KB |
Output is correct |
15 |
Correct |
29 ms |
5296 KB |
Output is correct |
16 |
Correct |
19 ms |
3640 KB |
Output is correct |
17 |
Correct |
20 ms |
3736 KB |
Output is correct |
18 |
Correct |
33 ms |
5448 KB |
Output is correct |
19 |
Correct |
31 ms |
5284 KB |
Output is correct |
20 |
Correct |
19 ms |
3748 KB |
Output is correct |
21 |
Incorrect |
48 ms |
7752 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |