File tree 2 files changed +60
-0
lines changed
2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ We can use this technique in many problems. It's a pretty powerful technique.
29
29
- [ 壁抜け] ( https://atcoder.jp/contests/abc020/tasks/abc020_c )
30
30
- [ 001 - Yokan Party] ( https://atcoder.jp/contests/typical90/tasks/typical90_a )
31
31
- [ D - No Need] ( https://atcoder.jp/contests/abc056/tasks/arc070_b )
32
+ - [ Gluttony - AtCoder ABC144E] ( https://atcoder.jp/contests/abc144/tasks/abc144_e )
32
33
33
34
34
35
## Dice
You can’t perform that action at this time.
0 commit comments