#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<" "<<#__VA_ARGS__<<" - ", _do(__VA_ARGS__)
template <typename T> void _do( T && x) {cerr<<x<<endl;}
template <typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
const int maxn = 3e5+5;
ll a[maxn], b[maxn];
int n,m;
bool can(ll X) {
__int128 pool = 0;
REP(i,n) {
ll keep = min(X / a[i], m);
ll need = (X - a[i] * keep + b[i]-1) / b[i];
ll g1 = m-keep-need;
keep = min((X+a[i]-1) / a[i], m);
need = (max(0ll, X - a[i] * keep) + b[i]-1) / b[i];
ll g2 = m-keep-need;
pool += max(g1, g2);
bug(i, g1, g2);
}
bug(X, pool);
return pool >= 0;
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
bug(1,2);
cin>>n>>m;
REP(i,n) cin>>a[i];
REP(i,n) cin>>b[i], MX(a[i], b[i]);
ll l = 0, r = 4e18;
while (l!=r) {
ll mid = (l+r)/2;
if (can(mid)) {
l = mid+1;
}else{
r = mid;
}
}
cout<<l-1<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
8 ms |
400 KB |
Output is correct |
11 |
Correct |
495 ms |
5112 KB |
Output is correct |
12 |
Correct |
494 ms |
4992 KB |
Output is correct |
13 |
Correct |
478 ms |
4932 KB |
Output is correct |
14 |
Correct |
606 ms |
5004 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
727 ms |
6252 KB |
Output is correct |
17 |
Correct |
504 ms |
11460 KB |
Output is correct |
18 |
Correct |
502 ms |
10692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
727 ms |
6252 KB |
Output is correct |
3 |
Correct |
504 ms |
11460 KB |
Output is correct |
4 |
Correct |
502 ms |
10692 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
251 ms |
2688 KB |
Output is correct |
14 |
Correct |
167 ms |
1868 KB |
Output is correct |
15 |
Correct |
133 ms |
1484 KB |
Output is correct |
16 |
Correct |
105 ms |
1244 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
12 ms |
396 KB |
Output is correct |
23 |
Correct |
9 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
8 ms |
400 KB |
Output is correct |
11 |
Correct |
495 ms |
5112 KB |
Output is correct |
12 |
Correct |
494 ms |
4992 KB |
Output is correct |
13 |
Correct |
478 ms |
4932 KB |
Output is correct |
14 |
Correct |
606 ms |
5004 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
251 ms |
2688 KB |
Output is correct |
24 |
Correct |
167 ms |
1868 KB |
Output is correct |
25 |
Correct |
133 ms |
1484 KB |
Output is correct |
26 |
Correct |
105 ms |
1244 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
12 ms |
396 KB |
Output is correct |
33 |
Correct |
9 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
324 KB |
Output is correct |
35 |
Correct |
727 ms |
6252 KB |
Output is correct |
36 |
Correct |
504 ms |
11460 KB |
Output is correct |
37 |
Correct |
502 ms |
10692 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
0 ms |
216 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
1 ms |
324 KB |
Output is correct |
45 |
Correct |
9 ms |
460 KB |
Output is correct |
46 |
Correct |
18 ms |
692 KB |
Output is correct |
47 |
Correct |
2 ms |
352 KB |
Output is correct |
48 |
Correct |
85 ms |
2096 KB |
Output is correct |
49 |
Correct |
1 ms |
316 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
9 ms |
412 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
0 ms |
320 KB |
Output is correct |
54 |
Correct |
1 ms |
204 KB |
Output is correct |
55 |
Correct |
246 ms |
5460 KB |
Output is correct |
56 |
Correct |
167 ms |
3132 KB |
Output is correct |
57 |
Correct |
209 ms |
3144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
251 ms |
2688 KB |
Output is correct |
10 |
Correct |
167 ms |
1868 KB |
Output is correct |
11 |
Correct |
133 ms |
1484 KB |
Output is correct |
12 |
Correct |
105 ms |
1244 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
12 ms |
396 KB |
Output is correct |
19 |
Correct |
9 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
727 ms |
6252 KB |
Output is correct |
22 |
Correct |
504 ms |
11460 KB |
Output is correct |
23 |
Correct |
502 ms |
10692 KB |
Output is correct |
24 |
Correct |
89 ms |
1928 KB |
Output is correct |
25 |
Correct |
259 ms |
4932 KB |
Output is correct |
26 |
Correct |
55 ms |
1408 KB |
Output is correct |
27 |
Correct |
502 ms |
10892 KB |
Output is correct |
28 |
Correct |
504 ms |
10820 KB |
Output is correct |
29 |
Correct |
504 ms |
10820 KB |
Output is correct |
30 |
Correct |
529 ms |
10812 KB |
Output is correct |
31 |
Correct |
573 ms |
10792 KB |
Output is correct |
32 |
Correct |
743 ms |
6168 KB |
Output is correct |
33 |
Correct |
651 ms |
11560 KB |
Output is correct |
34 |
Correct |
765 ms |
6168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
8 ms |
400 KB |
Output is correct |
11 |
Correct |
495 ms |
5112 KB |
Output is correct |
12 |
Correct |
494 ms |
4992 KB |
Output is correct |
13 |
Correct |
478 ms |
4932 KB |
Output is correct |
14 |
Correct |
606 ms |
5004 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
251 ms |
2688 KB |
Output is correct |
24 |
Correct |
167 ms |
1868 KB |
Output is correct |
25 |
Correct |
133 ms |
1484 KB |
Output is correct |
26 |
Correct |
105 ms |
1244 KB |
Output is correct |
27 |
Correct |
2 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
12 ms |
396 KB |
Output is correct |
33 |
Correct |
9 ms |
460 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
216 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
324 KB |
Output is correct |
41 |
Correct |
9 ms |
460 KB |
Output is correct |
42 |
Correct |
18 ms |
692 KB |
Output is correct |
43 |
Correct |
2 ms |
352 KB |
Output is correct |
44 |
Correct |
85 ms |
2096 KB |
Output is correct |
45 |
Correct |
1 ms |
316 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
9 ms |
412 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
0 ms |
320 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
246 ms |
5460 KB |
Output is correct |
52 |
Correct |
167 ms |
3132 KB |
Output is correct |
53 |
Correct |
209 ms |
3144 KB |
Output is correct |
54 |
Correct |
89 ms |
1928 KB |
Output is correct |
55 |
Correct |
259 ms |
4932 KB |
Output is correct |
56 |
Correct |
55 ms |
1408 KB |
Output is correct |
57 |
Correct |
502 ms |
10892 KB |
Output is correct |
58 |
Correct |
504 ms |
10820 KB |
Output is correct |
59 |
Correct |
504 ms |
10820 KB |
Output is correct |
60 |
Correct |
529 ms |
10812 KB |
Output is correct |
61 |
Correct |
573 ms |
10792 KB |
Output is correct |
62 |
Correct |
743 ms |
6168 KB |
Output is correct |
63 |
Correct |
651 ms |
11560 KB |
Output is correct |
64 |
Correct |
765 ms |
6168 KB |
Output is correct |
65 |
Correct |
1 ms |
324 KB |
Output is correct |
66 |
Correct |
727 ms |
6252 KB |
Output is correct |
67 |
Correct |
504 ms |
11460 KB |
Output is correct |
68 |
Correct |
502 ms |
10692 KB |
Output is correct |
69 |
Correct |
64 ms |
1448 KB |
Output is correct |
70 |
Correct |
17 ms |
592 KB |
Output is correct |
71 |
Correct |
1 ms |
332 KB |
Output is correct |
72 |
Correct |
85 ms |
1728 KB |
Output is correct |
73 |
Correct |
19 ms |
588 KB |
Output is correct |
74 |
Correct |
2 ms |
332 KB |
Output is correct |
75 |
Correct |
523 ms |
10792 KB |
Output is correct |
76 |
Correct |
530 ms |
10788 KB |
Output is correct |
77 |
Correct |
535 ms |
10928 KB |
Output is correct |
78 |
Correct |
544 ms |
10820 KB |
Output is correct |
79 |
Correct |
592 ms |
10820 KB |
Output is correct |
80 |
Correct |
581 ms |
10676 KB |
Output is correct |
81 |
Correct |
623 ms |
8756 KB |
Output is correct |
82 |
Correct |
745 ms |
8800 KB |
Output is correct |