제출 #820164

#제출 시각아이디문제언어결과실행 시간메모리
820164rnl42Cake 3 (JOI19_cake3)C++14
24 / 100
4056 ms7996 KiB
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define int long long

struct Perle {
    int t, c;
    bool operator<(const Perle& other) {
        return t < other.t;
    }
};

int N, M;
vector<Perle> perles;

signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> N >> M;
    perles.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> perles[i].c >> perles[i].t;
    }
    sort(perles.begin(), perles.end());
    int ans = -1e18;
    for (int deb = 0; deb < N; deb++) {
        int sum = 0;
        priority_queue<int,vector<int>,greater<int>> pq;
        for (int fin = deb; fin < N; fin++) {
            if (fin > deb+M-1) {
                sum -= pq.top();
                pq.pop();
            }
            pq.push(perles[fin].c);
            sum += perles[fin].c;
            if (fin >= deb+M-1) {
                ans = max(ans, sum-2*abs(perles[deb].t-perles[fin].t));
            }
        }
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...