Submission #982539

#TimeUsernameProblemLanguageResultExecution timeMemory
982539Jarif_RahmanCake 3 (JOI19_cake3)C++17
24 / 100
4102 ms8244 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<pair<ll, ll>> cv(n); for(auto &[c, v]: cv) cin >> v >> c; sort(cv.begin(), cv.end()); ll ans = -1e18; for(int i = 0; i < n; i++){ ll sum = 0; priority_queue<ll> pq; for(int j = i; j < n; j++){ if(pq.size() < m) sum+=cv[j].second, pq.push(-cv[j].second); else if(cv[j].second > -pq.top()){ sum+=pq.top(); pq.pop(); sum+=cv[j].second; pq.push(-cv[j].second); } if(j-i+1 >= m) ans = max(ans, sum-(cv[j].first-cv[i].first)*2); } } cout << ans << "\n"; }

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:22:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |             if(pq.size() < m) sum+=cv[j].second, pq.push(-cv[j].second);
      |                ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...