Submission #129020

#TimeUsernameProblemLanguageResultExecution timeMemory
129020PeppaPigCake 3 (JOI19_cake3)C++14
5 / 100
4006 ms512 KiB
#include <bits/stdc++.h>
 
#define long long long
#define pii pair<long, long>
#define x first
#define y second
 
using namespace std;
 
const int N = 2e5+5;
 
int n, m;
pii v[N];
long ans = -1e18;
 
int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++) scanf("%lld %lld", &v[i].x, &v[i].y);
    sort(v + 1, v + n + 1, [&](const pii &a, const pii &b) {
        return a.y < b.y;    
    });
    for(int i = 1; i <= n; i++) {
        multiset<pii, greater<pii> > S;
        for(int j = i + 1; j <= n; j++) {
            if(S.size() >= m - 2) {
                long ret = 0;
                auto it = S.begin();
                for(int i = 0; i < m - 2; i++, it++)
                    ret += it->x;
                ret -= 2 * (v[j].y - v[i].y);
                ret += v[i].x + v[j].x;
                ans = max(ans, ret);
            }
            S.emplace(v[j]);
        }
    }
    printf("%lld\n", ans);
 
    return 0;
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:25:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(S.size() >= m - 2) {
                ~~~~~~~~~^~~~~~~~
cake3.cpp:17: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:18:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%lld %lld", &v[i].x, &v[i].y);
                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...