# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47562 | fallingstar | 학교 설립 (IZhO13_school) | C++17 | 459 ms | 13164 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
Problem: Schools
Source: IX Zhautykov Olympiad on Mathematics, Physics and Informatics (IZhO) 2013, day 1, problem C
*/
#include <iostream>
#include <algorithm>
#include <set>
#define long long long
using namespace std;
const int N = 3e5 + 2;
int n, m1, m2;
pair<int, int> a[N];
long fa[N], fb[N];
int main()
{
cin >> n >> m1 >> m2;
for (int i = 1; i <= n; ++i)
cin >> a[i].first >> a[i].second;
sort(a + 1, a + 1 + n, [](pair<int, int> a, pair<int, int> b) {
return a.first - a.second > b.first - b.second;
});
set<pair<int, int> > s;
for (int i = 1; i <= n; ++i)
{
fa[i] = fa[i - 1] + a[i].first;
s.insert({a[i].first, i});
if (s.size() > m1)
{
fa[i] -= s.begin()->first;
s.erase(s.begin());
}
}
s.clear();
for (int i = n; i >= 1; --i)
{
fb[i] = fb[i + 1] + a[i].second;
s.insert({a[i].second, i});
if (s.size() > m2)
{
fb[i] -= s.begin()->first;
s.erase(s.begin());
}
}
long res = 0;
for (int i = m1; i + m2 <= n; ++i)
res = max(res, fa[i] + fb[i + 1]);
cout << res;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |