0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:28:48 +00:00

750. [2018国庆雅礼集训10-6T1] Merchant

https://sjzezoj.com/submission/20508
This commit is contained in:
Baoshuo Ren 2021-08-21 14:48:17 +08:00 committed by Baoshuo Ren
parent 40decd147f
commit bc3cfa7174
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

42
S2OJ/750/750.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, k[1000005], b[1000005];
long long c[1000005], s, ans;
bool check(int t) {
long long sum = 0;
for (int i = 0; i < n; i++) {
c[i] = 1ll * k[i] * t + b[i];
}
nth_element(c, c + m, c + n, greater<long long>());
for (int i = 0; i < m; i++) {
if (c[i] >= 0) sum += c[i];
if (sum >= s) return true;
}
return false;
}
int main() {
cin >> n >> m >> s;
for (int i = 0; i < n; i++) {
cin >> k[i] >> b[i];
}
if (check(0)) {
cout << 0 << endl;
exit(0);
}
int l = 0, r = 1e9 + 1;
while (l <= r) {
int mid = l + r >> 1;
if (check(mid)) {
r = mid - 1;
ans = mid;
} else {
l = mid + 1;
}
}
cout << ans << endl;
return 0;
}