Submission #980898

#TimeUsernameProblemLanguageResultExecution timeMemory
980898happy_nodeCake 3 (JOI19_cake3)C++17
0 / 100
1 ms2392 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX=2e5+5; int N,M; ll V[MX],C[MX]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin>>N>>M; for(int i=1;i<=N;i++) cin>>V[i]>>C[i]; vector<int> ord; for(int i=1;i<=N;i++) ord.push_back(i); sort(ord.begin(),ord.end(),[&](int i, int j){ return C[i]<C[j]; }); multiset<ll> st; ll sum=0,ans=0; for(int i=1;i<=M;i++) st.insert(0); for(auto i:ord) { sum+=V[i]; st.insert(V[i]); sum-=*st.begin(); st.erase(st.begin()); ans=max(ans,sum-2*C[i]); // trying to insert Vi + 2Ci ll cur=0; while(st.size()) { if(cur+*st.rbegin()<V[i]+2*C[i]) { cur+=*st.rbegin(); sum-=*st.rbegin(); st.erase(st.find(*st.rbegin())); } else { ll k=*st.rbegin(); sum-=k; st.erase(st.find(k)); cur+=k; cur-=V[i]+2*C[i]; sum+=cur; st.insert(cur); break; } } sum+=V[i]+2*C[i]; st.insert(V[i]+2*C[i]); while(st.size()<M) st.insert(0); } cout<<ans<<'\n'; }

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:63:18: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |   while(st.size()<M) st.insert(0);
      |         ~~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...