# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
446003 | Aryan_Raina | 학교 설립 (IZhO13_school) | C++17 | 130 ms | 12116 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define ld long double
#define ar array
#define all(a) a.begin(), a.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e15;
const int MOD = 1e9+7;
void solve() {
int N, M, S; cin >> N >> M >> S;
vector<ar<int,2>> shit(N);
for (ar<int,2> &i : shit) cin >> i[0] >> i[1];
sort(shit.begin(), shit.end(), [&](ar<int,2> x, ar<int,2> y) {
return x[0] - x[1] > y[0] - y[1];
});
vector<int> ansA(N,0), ansB(N,0);
priority_queue<int> pq;
pq.push(-(ansA[0] = shit[0][0]));
if (pq.size() > M) {
ansA[0] += pq.top(); pq.pop();
}
for (int i = 1; i < N; i++) {
ansA[i] = ansA[i-1] + shit[i][0];
pq.push(-shit[i][0]);
if (pq.size() > M) {
ansA[i] += pq.top(); pq.pop();
}
}
priority_queue<int>().swap(pq);
pq.push(-(ansB[N-1] = shit[N-1][1]));
if (pq.size() > S) {
ansB[N-1] += pq.top(); pq.pop();
}
for (int i = N-2; i >= 0; i--) {
ansB[i] = ansB[i+1] + shit[i][1];
pq.push(-shit[i][1]);
if (pq.size() > S) {
ansB[i] += pq.top(); pq.pop();
}
}
int ans = max(ansB[0], ansA[N-1]);
for (int i = 0; i < N-1; i++)
ans = max(ans, ansA[i] + ansB[i+1]);
cout << ans << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; //cin >> t;
while (t--) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |