#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
#define sp << ' ' <<
#define nl << '\n'
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) {return (a.F - a.S < b.F - b.S ? 1 : 0);}
void solve () {
int n, m, s; cin >> n >> m >> s;
vector<pair<int, int>> v(n);
for (auto &i : v) cin >> i.F >> i.S;
sort(all(v), cmp);
int ans = 0;
int sum = 0;
pq<int> q;
for (int i = 0; i < n; i++) {
q.push(-v[i].S);
sum += v[i].S;
while (q.size() > s) {sum += q.top(); q.pop();}
v[i].S = sum;
}
sum = 0;
pq<int> ().swap(q);
for (int i = n-1; i >= 0; i--) {
q.push(-v[i].F);
sum += v[i].F;
while (q.size() > m) {sum += q.top(); q.pop();}
ans = max(ans, sum + (i ? v[i-1].S : 0));
}
cout << ans;
}
signed main() {IOS solve(); return 0;}
Compilation message
school.cpp: In function 'void solve()':
school.cpp:36:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
36 | while (q.size() > s) {sum += q.top(); q.pop();}
| ~~~~~~~~~^~~
school.cpp:46:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
46 | while (q.size() > m) {sum += q.top(); q.pop();}
| ~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
11 ms |
1360 KB |
Output is correct |
14 |
Correct |
29 ms |
1924 KB |
Output is correct |
15 |
Correct |
40 ms |
2896 KB |
Output is correct |
16 |
Correct |
49 ms |
6456 KB |
Output is correct |
17 |
Correct |
62 ms |
5472 KB |
Output is correct |
18 |
Correct |
70 ms |
5768 KB |
Output is correct |
19 |
Correct |
77 ms |
6052 KB |
Output is correct |
20 |
Correct |
98 ms |
6720 KB |
Output is correct |