Submission #128876

#TimeUsernameProblemLanguageResultExecution timeMemory
128876PlurmCake 3 (JOI19_cake3)C++11
0 / 100
9 ms376 KiB
#include <bits/stdc++.h>
using namespace std;
long long sv[5048][5048];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int v,c;
    vector<pair<int,int> > pieces;
    for(int i = 0; i < n; i++){
        scanf("%d%d",&v,&c);
      if(v < 0 || c < 0) throw "fuck";
        pieces.push_back(make_pair(v,c));
    }
    sort(pieces.begin(), pieces.end(), [](pair<int,int> x, pair<int,int> y){
        return x.second < y.second;
    });
    long long ans = 0ll;
    for(int i = 0; i < n; i++){
        long long highsum = 0ll;
        for(int j = i+m-1; j < n; j++){
            priority_queue<int, vector<int>, greater<int> > pq;
            for(int k = i; k <= j; k++){
                pq.push(pieces[k].first);
            }
            while(pq.size() > m) pq.pop();
            while(!pq.empty()){
                highsum += 1ll * pq.top();
                pq.pop();
            }
            highsum -= 2ll * abs(pieces[i].second - pieces[j].second);
            ans = max(ans, highsum);
            highsum = 0ll;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:25:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(pq.size() > m) pq.pop();
                   ~~~~~~~~~~^~~
cake3.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
cake3.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&v,&c);
         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...