# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
647418 |
2022-10-02T13:23:39 Z |
LeonaRaging |
Feast (NOI19_feast) |
C++14 |
|
45 ms |
4956 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[0] = a[1];
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 |
28 ms |
2644 KB |
Output is correct |
2 |
Correct |
28 ms |
2716 KB |
Output is correct |
3 |
Correct |
28 ms |
2772 KB |
Output is correct |
4 |
Correct |
28 ms |
2688 KB |
Output is correct |
5 |
Correct |
28 ms |
2740 KB |
Output is correct |
6 |
Correct |
28 ms |
2636 KB |
Output is correct |
7 |
Correct |
27 ms |
2620 KB |
Output is correct |
8 |
Correct |
28 ms |
2756 KB |
Output is correct |
9 |
Correct |
28 ms |
2672 KB |
Output is correct |
10 |
Correct |
28 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
2708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
2644 KB |
Output is correct |
2 |
Correct |
28 ms |
2716 KB |
Output is correct |
3 |
Correct |
28 ms |
2772 KB |
Output is correct |
4 |
Correct |
28 ms |
2688 KB |
Output is correct |
5 |
Correct |
28 ms |
2740 KB |
Output is correct |
6 |
Correct |
28 ms |
2636 KB |
Output is correct |
7 |
Correct |
27 ms |
2620 KB |
Output is correct |
8 |
Correct |
28 ms |
2756 KB |
Output is correct |
9 |
Correct |
28 ms |
2672 KB |
Output is correct |
10 |
Correct |
28 ms |
2636 KB |
Output is correct |
11 |
Incorrect |
19 ms |
2708 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |