제출 #129026

#제출 시각아이디문제언어결과실행 시간메모리
129026PeppaPigCake 3 (JOI19_cake3)C++14
0 / 100
2 ms376 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;
multiset<pii> S1, S2;
 
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;    
    });
    long sum = 0;
    for(int i = 1; i <= n; i++) {
        S1.emplace(v[i].x, i);
        S2.emplace(v[i].y, i);
        sum += v[i].x;
        if(S1.size() > m) {
            long ret1 = sum - S1.begin()->x - 2 * (S2.rbegin()->x - S2.begin()->x);
            long ret2 = sum - v[S2.begin()->y].x - 2 * (S2.rbegin()->x - next(S2.begin())->x);
            if(ret1 > ret2) sum -= S1.begin()->x, S2.erase(S2.find(pii(v[S1.begin()->y].y, S1.begin()->y))), S1.erase(S1.begin());
            else sum -= v[S2.begin()->y].x, S1.erase(S1.find(pii(v[S2.begin()->y].x, S2.begin()->y))), S2.erase(S2.begin());
        }
        ans = max(ans, sum - 2 * (S2.rbegin()->x - S2.begin()->x));
    }
    printf("%lld\n", ans);
 
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

cake3.cpp: In function 'int main()':
cake3.cpp:28:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(S1.size() > m) {
            ~~~~~~~~~~^~~
cake3.cpp:18: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:19: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...