# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
21855 | 2017-04-26T12:38:54 Z | ulna | 학교 설립 (IZhO13_school) | C++11 | 176 ms | 10208 KB |
#include <bits/stdc++.h> using namespace std; // why am I so weak int n, m, s; int a[300055], b[300055]; int group[300055]; struct compare1 { bool operator () (const int &u, const int &v) const { return a[u] < a[v]; } } ; struct compare2 { bool operator () (const int &u, const int &v) const { return b[u] < b[v]; } } ; int main() { scanf("%d %d %d", &n, &m, &s); for (int i = 0; i < n; i++) { scanf("%d %d", &a[i], &b[i]); } vector<int> vec(n); for (int i = 0; i < n; i++) vec[i] = i; sort(vec.begin(), vec.end(), [&] (int u, int v) { return a[u] > a[v]; }); long long res = 0ll; // from a->b, nothing->a, -a[i] + b[i] + a[j] // from nothing->b, +b[j] priority_queue<int> a; priority_queue<int, vector<int>, compare1> c; priority_queue<int, vector<int>, compare2> d; for (int i = 0; i < m; i++) { res += ::a[vec[i]]; group[vec[i]] = 1; a.push(-::a[vec[i]] + b[vec[i]]); } for (int i = m; i < n; i++) { c.push(vec[i]); d.push(vec[i]); } for (int i = 0; i < s; i++) { while (group[c.top()] != 0) c.pop(); while (group[d.top()] != 0) d.pop(); if (a.empty() || a.top() + ::a[c.top()] < b[d.top()]) { res += b[d.top()]; group[d.top()] = 2; d.pop(); } else { res += a.top() + ::a[c.top()]; group[c.top()] = 1; a.pop(); a.push(-::a[c.top()] + b[c.top()]); c.pop(); } } printf("%lld\n", res); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 5540 KB | Output is correct |
2 | Correct | 0 ms | 5540 KB | Output is correct |
3 | Correct | 0 ms | 5540 KB | Output is correct |
4 | Correct | 0 ms | 5540 KB | Output is correct |
5 | Correct | 0 ms | 5540 KB | Output is correct |
6 | Correct | 0 ms | 5540 KB | Output is correct |
7 | Correct | 0 ms | 5676 KB | Output is correct |
8 | Correct | 0 ms | 5696 KB | Output is correct |
9 | Correct | 0 ms | 5540 KB | Output is correct |
10 | Correct | 0 ms | 5540 KB | Output is correct |
11 | Correct | 0 ms | 5676 KB | Output is correct |
12 | Correct | 0 ms | 5680 KB | Output is correct |
13 | Correct | 19 ms | 5956 KB | Output is correct |
14 | Correct | 43 ms | 7344 KB | Output is correct |
15 | Correct | 76 ms | 8808 KB | Output is correct |
16 | Correct | 169 ms | 9152 KB | Output is correct |
17 | Correct | 159 ms | 9896 KB | Output is correct |
18 | Correct | 159 ms | 9980 KB | Output is correct |
19 | Correct | 159 ms | 10056 KB | Output is correct |
20 | Correct | 176 ms | 10208 KB | Output is correct |