제출 #249440

#제출 시각아이디문제언어결과실행 시간메모리
249440cheehengCake 3 (JOI19_cake3)C++14
24 / 100
4048 ms4032 KiB
#include <bits/stdc++.h>
using namespace std;

typedef pair<long long, long long> ii;

ii CV[200005];

int N, M;

priority_queue<long long, vector<int>, greater<int> > pq;
long long sum = 0;
void init(){
    pq = priority_queue<long long, vector<int>, greater<int> >();
    sum = 0;
}

long long insert1(long long x){
    pq.push(x);
    sum += x;
    if(pq.size() > M){
        sum -= pq.top();
        pq.pop();
    }
}

long long getSum(){
    return sum;
}

int getSize(){
    return (int)pq.size();
}

int main(){
    scanf("%d%d", &N, &M);

    for(int i = 0; i < N; i ++){
        long long V, C;
        scanf("%lld%lld", &V, &C);
        CV[i] = ii(C, V);
    }

    sort(CV, CV+N);

    long long ans = -1LL << 62;
    for(int i = 0; i < N; i ++){
        init();
        for(int j = i; j < N; j ++){
            insert1(CV[j].second);
            if(getSize() == M){
                ans = max(ans, getSum() - 2*(CV[j].first - CV[i].first));
            }
        }
    }

    printf("%lld", ans);
    return 0;
}

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

cake3.cpp: In function 'long long int insert1(long long int)':
cake3.cpp:20:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(pq.size() > M){
        ~~~~~~~~~~^~~
cake3.cpp:24:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
cake3.cpp: In function 'int main()':
cake3.cpp:35: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:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &V, &C);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...