# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
171591 | davitmarg | 학교 설립 (IZhO13_school) | C++17 | 192 ms | 6132 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 300005;
int n, m, s, k;
LL ans1,ans2;
pair<LL, LL> a[N];
multiset<LL> B;
int main()
{
cin >> n >> m >> s;
k = n - m - s;
for (int i = 1; i <= n; i++)
scanf("%lld%lld", &a[i].first, &a[i].second);
sort(a + 1, a + 1 + n, [](pair<LL, LL> a, pair<LL, LL> b) {
return a.first - a.second > b.first - b.second;
});
sort(a + 1, a + 1 + m+k);
reverse(a + 1, a + 1 + m+k);
for (int i = 1; i <= m; i++)
ans1 += a[i].first;
for (int i = 1; i <= n; i++)
swap(a[i].first, a[i].second);
sort(a+1+m,a+1+n);
for (int i = n; i > m + k; i--)
ans1 += a[i].first;
sort(a + 1, a + 1 + n, [](pair<LL, LL> a, pair<LL, LL> b) {
return a.first - a.second > b.first - b.second;
});
swap(m,s);
sort(a + 1, a + 1 + m + k);
reverse(a + 1, a + 1 + m + k);
for (int i = 1; i <= m; i++)
ans2 += a[i].first;
for (int i = 1; i <= n; i++)
swap(a[i].first, a[i].second);
sort(a + 1 + m, a + 1 + n);
for (int i = n; i > m + k; i--)
ans2 += a[i].first;
cout << max(ans1,ans2) << endl;
return 0;
}
/*
4 1 1
100 0
550 500
500 550
0 100
3 1 1
100 0
500 550
0 100
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |