#include <bits/stdc++.h>
#define pb push_back
#define vii vector<int>
#define pll pair<ll, ll>
#define pii pair< ll, pair< ll, ll > >
#define fi first
#define se second
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const ll mod = 1e16+7;
using namespace std;
const ll N = 2e5;
ll tong, m, n, k, ans=mod, p, t, b[N], c[N], a[N], rb[N], ra[N], lab[N];
pll d[N*3];
//bool check;
string s;
vector<ll> kq, pre;
priority_queue< ll > pb, pa;
void sol()
{
cin >> k >> n >> m;
p=k-n-m;
for(int i = 1 ; i <= k ;i ++)
{
cin >> a[i] >> b[i] ;
a[i]*=-1;
b[i]*=-1;
c[i]=0;
d[i].se = i;
d[i].fi = a[i] - b[i];
tong += c[i];
}
sort(d+1, d+1+k,greater<pair<int,int>>());
// cout <<'\n';
// for(int i=1;i<=k;i++) cout << d[i].se<<' '<<a[d[i].se]-c[d[i].se]<<' '<<b[d[i].se]-c[d[i].se]<<'\n';
// cout << '\n';
for(int i = 1; i <= k; i ++)
{
pb.push(b[d[i].se] - c[d[i].se]);
rb[i] = rb[i-1] + b[d[i].se] - c[d[i].se];
while(pb.size() > m)
{
rb[i] -= pb.top();
pb.pop();
}
}
for(int i = k; i > 0; i --)
{
pa.push(a[d[i].se] - c[d[i].se]);
ra[i] = ra[i+1] + a[d[i].se] - c[d[i].se];
while(pa.size() > n)
{
ra[i] -= pa.top();
pa.pop();
}
}
for(int i = m; i <= k - n; i ++)
{
//if(i==k-n) cout << ra[i+1]<<' '<<rb[i]<<'\n';
ans = min(ans, tong + ra[i+1] + rb[i]);
}
cout << -ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest;
ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
Compilation message
school.cpp: In function 'void sol()':
school.cpp:45:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
45 | while(pb.size() > m)
| ^
school.cpp:55:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
55 | while(pa.size() > n)
| ~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
3 ms |
732 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
700 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
17 ms |
3044 KB |
Output is correct |
14 |
Correct |
36 ms |
5768 KB |
Output is correct |
15 |
Correct |
65 ms |
10884 KB |
Output is correct |
16 |
Correct |
84 ms |
13760 KB |
Output is correct |
17 |
Incorrect |
49 ms |
10592 KB |
Output isn't correct |
18 |
Incorrect |
38 ms |
10616 KB |
Output isn't correct |
19 |
Incorrect |
43 ms |
10692 KB |
Output isn't correct |
20 |
Incorrect |
42 ms |
10664 KB |
Output isn't correct |