Skip to content

Commit 009906b

Browse files
authored
Merge pull request #457 from xirc/atcoder/abc144E
AtCoder/ABC144E
2 parents 3f026ca + 947c6ae commit 009906b

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

atcoder/abc144/E/main.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <bits/stdc++.h>
2+
3+
inline int64_t binary_search(
4+
std::function<bool(int64_t)> const& predicate,
5+
int64_t ng,
6+
int64_t ok
7+
) {
8+
assert(!predicate(ng));
9+
assert(predicate(ok));
10+
while (abs(ok - ng) > 1) {
11+
auto m = (ok + ng) / 2;
12+
if (predicate(m)) ok = m;
13+
else ng = m;
14+
}
15+
return ok;
16+
}
17+
18+
using namespace std;
19+
using ll = int64_t;
20+
using ff = long double;
21+
22+
int N; ll K;
23+
vector<int> A, F;
24+
25+
bool pass(ll M) {
26+
ll require = 0;
27+
for (int i = 0; i < N; ++i) {
28+
if (ll(A[i]) * F[i] <= M) continue;
29+
ll x = A[i] - M / F[i];
30+
require += x;
31+
}
32+
return require <= K;
33+
}
34+
35+
ll solve() {
36+
ll acc = accumulate(A.begin(), A.end(), ll(0), plus<ll>());
37+
if (acc <= K) return 0;
38+
39+
sort(A.begin(), A.end());
40+
reverse(A.begin(), A.end());
41+
sort(F.begin(), F.end());
42+
ll ng = 0, ok = 1e13;
43+
return binary_search(pass, ng, ok);
44+
}
45+
46+
int main() {
47+
ios_base::sync_with_stdio(false);
48+
cin.tie(0); cout.tie(0);
49+
50+
cin >> N >> K;
51+
A.assign(N, 0);
52+
F.assign(N, 0);
53+
for (auto &a : A) cin >> a;
54+
for (auto &f : F) cin >> f;
55+
56+
cout << solve() << endl;
57+
58+
return 0;
59+
}

lib/cpalgo/util/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ We can use this technique in many problems. It's a pretty powerful technique.
2929
- [壁抜け](https://atcoder.jp/contests/abc020/tasks/abc020_c)
3030
- [001 - Yokan Party](https://atcoder.jp/contests/typical90/tasks/typical90_a)
3131
- [D - No Need](https://atcoder.jp/contests/abc056/tasks/arc070_b)
32+
- [Gluttony - AtCoder ABC144E](https://atcoder.jp/contests/abc144/tasks/abc144_e)
3233

3334

3435
## Dice

0 commit comments

Comments
 (0)