Submission #1110047

#TimeUsernameProblemLanguageResultExecution timeMemory
1110047adkjtFeast (NOI19_feast)C++14
12 / 100
95 ms4664 KiB
#include<bits/stdc++.h> using namespace std; #define f first #define s second #define pii pair<int,int> #define ll long long int a[311111]; priority_queue<ll,vector<ll>,greater<ll>> pq; int main() { int n,k; cin>>n>>k; ll ans=0,cnt=0,cur=0; for(int i=1; i<=n; i++){ cin>>a[i]; if(a[i]>=0&&a[i-1]>=0) { cur+=a[i]; } else if(a[i]<0&&a[i-1]<0) { cur-=a[i]; } else if(a[i]>=0&&a[i-1]<0){ pq.push(cur); cur=a[i]; } else if(a[i]<0&&a[i-1]>=0) { pq.push(cur); ans+=cur; cnt++; cur=-a[i]; } //cout<<ans<<'\n'; } if(a[n]>=0) pq.push(cur),cnt++,ans+=cur; //cout<<'\n'; while(cnt>k) { //cout<<ans<<'\n'; int now=pq.top(); ans-=now; cnt--; pq.pop(); } cout<<max(ans,(ll)0); }
#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...