Submission #128790

#TimeUsernameProblemLanguageResultExecution timeMemory
128790win11905Cake 3 (JOI19_cake3)C++11
24 / 100
4067 ms5912 KiB
#include <bits/stdc++.h>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
 
const int N = 1e5+5;
 
int n, m;
vector<pii> vec;
 
int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1, v, c; i <= n; ++i) {
        scanf("%d %d", &v, &c);
        vec.emplace_back(v, c);
    }
    sort(vec.begin(), vec.end(), [&](const pii &a, const pii &b) {
        return a.y < b.y;      
    });
    long ans = -1e18;
    for(int i = 0; i < n; ++i) {
        priority_queue<int, vector<int>, greater<int> > Q;
        long sum = 0;
        for(int j = i; j < n; ++j) {
            sum += vec[j].x, Q.emplace(vec[j].x);
            if(Q.size() > m) sum -= Q.top(), Q.pop();
            if(Q.size() == m) ans = max(ans, sum - 2ll * (vec[j].y - vec[i].y));
        }
    }
    printf("%lld\n", ans);
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:28:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(Q.size() > m) sum -= Q.top(), Q.pop();
                ~~~~~~~~~^~~
cake3.cpp:29:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(Q.size() == m) ans = max(ans, sum - 2ll * (vec[j].y - vec[i].y));
                ~~~~~~~~~^~~~
cake3.cpp:14: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:16: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...