제출 #1288353

#제출 시각아이디문제언어결과실행 시간메모리
1288353aduwahiCake 3 (JOI19_cake3)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector<pair<ll,ll>> a(N); for (int i = 0; i < N; ++i) cin >> a[i].first >> a[i].second; // V, C // Sort by color (C) sort(a.begin(), a.end(), [](auto &x, auto &y){ return x.second < y.second; }); // Prefix sum of values vector<ll> pref(N+1, 0); for (int i = 0; i < N; ++i) pref[i+1] = pref[i] + a[i].first; ll ans = LLONG_MIN; // Slide window of length M for (int i = 0; i + M <= N; ++i) { ll sumV = pref[i+M] - pref[i]; ll penalty = a[i+M-1].second - a[i].second; ans = max(ans, sumV - penalty); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...