제출 #821800

#제출 시각아이디문제언어결과실행 시간메모리
821800rnl42Cake 3 (JOI19_cake3)C++14
24 / 100
4046 ms16436 KiB
#include <iostream> #include <algorithm> #include <queue> using namespace std; #define int long long #ifdef DEBUG #define dbg(x) cerr << #x << " = " << x << endl #define dbgln() cerr << "\n" #else #define dbg(x) void(0) #define dbgln() void(0) #endif using PQ = priority_queue<int,vector<int>,greater<int>>; struct Perle { int t, c; bool operator<(const Perle& other) { return t < other.t; } }; int N, M; vector<Perle> perles; int ans = -1e18; void rec(int l, int r, int optl, int optr) { if (l > r) return; int mid = (l+r)>>1; PQ pq; int sum = 0; int mini = -1e18; int opt = N-1; for (int i = mid; i <= optr; i++) { if (i >= mid+M) { sum -= pq.top(); pq.pop(); } pq.push(perles[i].c); sum += perles[i].c; if (i >= mid+M-1) { int p = sum-2*abs(perles[i].t-perles[mid].t); if (p > mini) { opt = i; mini = p; } } } ans = max(ans, mini); rec(l, mid-1, optl, min(opt, optr)); rec(mid+1, r, max(opt, optr), optr); } 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()); rec(0, N-1, M, N-1); cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...