Submission #647416

#TimeUsernameProblemLanguageResultExecution timeMemory
647416LeonaRagingFeast (NOI19_feast)C++14
12 / 100
48 ms7752 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...