Submission #112480

#TimeUsernameProblemLanguageResultExecution timeMemory
112480someone_aaCake 3 (JOI19_cake3)C++17
24 / 100
4019 ms9876 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define P pair<ll,ll> using namespace std; const int maxn = 200100; ll n, m; vector<P>v; int main() { cin>>n>>m; ll a, b; for(int i=0;i<n;i++) { cin>>a>>b; v.pb(mp(b, a)); } sort(v.begin(), v.end()); ll result = LLONG_MIN; for(int i=0;i<n;i++) { if(i < m-1) continue; multiset<ll>values; ll sum = 0LL; for(int j=i-1;j>=0;j--) { if(values.size() < m - 2) { sum += v[j].second; values.insert(v[j].second); } else { ll sum2 = sum + v[i].second + v[j].second; ll cost = 2*(v[i].first - v[j].first); result = max(result, sum2 - cost); ll minvalue = *(values.begin()); if(minvalue < v[j].second) { values.erase(values.find(minvalue)); values.insert(v[j].second); sum += v[j].second - minvalue; } } } } cout<<result; return 0; }

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:28:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(values.size() < m - 2) {
                ~~~~~~~~~~~~~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...