mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:08:47 +00:00
P3045 [USACO12FEB]Cow Coupons G
R56334026
This commit is contained in:
parent
c3f9ea426f
commit
737db35706
47
Luogu/problem/P3045/P3045.cpp
Normal file
47
Luogu/problem/P3045/P3045.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct node {
|
||||
long long p, q;
|
||||
} a[50005];
|
||||
|
||||
int n, k;
|
||||
long long m, ans;
|
||||
priority_queue<long long, vector<long long>, greater<long long>> q;
|
||||
|
||||
int main() {
|
||||
cin >> n >> k >> m;
|
||||
for (int i = 0; i < n; i++) {
|
||||
cin >> a[i].p >> a[i].q;
|
||||
}
|
||||
sort(a, a + n, [](node a, node b) { return a.q < b.q; });
|
||||
for (int i = 0; i < k; i++) {
|
||||
ans += a[i].q;
|
||||
q.push(a[i].p - a[i].q);
|
||||
if (ans > m) {
|
||||
cout << i << endl;
|
||||
exit(0);
|
||||
}
|
||||
if (i == n - 1) {
|
||||
cout << n << endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
sort(a + k, a + n, [](node a, node b) { return a.p < b.p; });
|
||||
for (int i = k; i < n; i++) {
|
||||
auto t = q.top();
|
||||
ans += a[i].p;
|
||||
if (a[i].q + t < a[i].p) {
|
||||
q.pop();
|
||||
ans += t + a[i].q - a[i].p;
|
||||
q.push(a[i].p - a[i].q);
|
||||
}
|
||||
if (ans > m) {
|
||||
cout << i << endl;
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
cout << n << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user