Submission #233046

#TimeUsernameProblemLanguageResultExecution timeMemory
233046oolimryCake 3 (JOI19_cake3)C++14
0 / 100
5 ms512 KiB
#include <bits/stdc++.h> #define int long long #define C first #define V second using namespace std; typedef pair<int,int> ii; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; ii arr[n]; for(int i = 0;i < n;i++) cin >> arr[i].V >> arr[i].C; sort(arr,arr+n); int ans = 0; for(int s = 0;s < n;s++){ priority_queue<int, vector<int>, greater<int> > pq; int acc = 0; for(int e = s+1;e < n;e++){ if((int) pq.size() >= m - 2){ if((int) pq.size() > m - 2){ acc -= pq.top(); pq.pop(); } ans = max(ans, acc + arr[s].V + arr[e].V - 2*arr[e].C + 2*arr[s].C); } pq.push(arr[e].V); acc += arr[e].V; } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...