| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1063549 | VMaksimoski008 | 학교 설립 (IZhO13_school) | C++17 | 195 ms | 16076 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
signed main() {
int n, a, b;
cin >> n >> a >> b;
vector<pii> v(n);
for(auto &x : v) cin >> x.first >> x.second;
sort(v.rbegin(), v.rend());
ll pref=0, suf=0;
priority_queue<int> pq;
for(int i=0; i<a; i++) {
pref += v[i].first;
pq.push(v[i].second - v[i].first);
}
multiset<ll> ms;
for(int i=a; i<n; i++) ms.insert(v[i].second), suf += v[i].second;
while(ms.size() > b) {
suf -= *ms.begin();
ms.erase(ms.begin());
}
ll ans = pref + suf;
for(int i=a; i<a+b; i++) {
pref += v[i].first;
pq.push(v[i].second - v[i].first);
pref += pq.top(); pq.pop();
suf -= *ms.lower_bound(v[i].second);
ms.erase(ms.lower_bound(v[i].second));
ans = max(ans, pref + suf);
}
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
