#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("WINTER.inp");
ofstream fout("WINTER.out");
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const ll mod = 1e9 + 7;
const int mxn = 3e5 + 5, mxv = 1e6;
ll n, m;
ll a[mxn + 1], b[mxn + 1];
bool ck(ll mid){
ll need = 0;
forr(i, 0, n){
ll have = max(a[i], b[i]) * m;
ll val = mid / max(a[i], b[i]);
if(mid % max(a[i], b[i]))val++;
need += min(val, m);
if(mid > have){
need += ceil((ld)(mid - have) / (ld)(b[i]));
}
if(need > n * m)return(false);
}
return(need <= n * m);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
forr(i, 0, n){
cin >> a[i];
}
forr(i, 0, n)cin >> b[i];
ll l = 1, r= 1e18, ans = 0;
while(l <= r){
ll mid = (l + r) >> 1;
if(ck(mid)){
ans = mid; l = mid + 1;
}else{
r = mid - 1;
}
}
cout << ans;
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
95 ms |
5096 KB |
Output is correct |
12 |
Correct |
100 ms |
10836 KB |
Output is correct |
13 |
Correct |
105 ms |
8924 KB |
Output is correct |
14 |
Correct |
100 ms |
8776 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
34 ms |
6152 KB |
Output is correct |
17 |
Correct |
124 ms |
11460 KB |
Output is correct |
18 |
Correct |
105 ms |
10816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
34 ms |
6152 KB |
Output is correct |
3 |
Correct |
124 ms |
11460 KB |
Output is correct |
4 |
Correct |
105 ms |
10816 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
50 ms |
2636 KB |
Output is correct |
14 |
Correct |
32 ms |
1880 KB |
Output is correct |
15 |
Correct |
25 ms |
1472 KB |
Output is correct |
16 |
Correct |
24 ms |
1184 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
4 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
95 ms |
5096 KB |
Output is correct |
12 |
Correct |
100 ms |
10836 KB |
Output is correct |
13 |
Correct |
105 ms |
8924 KB |
Output is correct |
14 |
Correct |
100 ms |
8776 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
50 ms |
2636 KB |
Output is correct |
24 |
Correct |
32 ms |
1880 KB |
Output is correct |
25 |
Correct |
25 ms |
1472 KB |
Output is correct |
26 |
Correct |
24 ms |
1184 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
452 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
34 ms |
6152 KB |
Output is correct |
36 |
Correct |
124 ms |
11460 KB |
Output is correct |
37 |
Correct |
105 ms |
10816 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
0 ms |
332 KB |
Output is correct |
45 |
Correct |
3 ms |
468 KB |
Output is correct |
46 |
Correct |
4 ms |
596 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
22 ms |
2116 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
3 ms |
444 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
52 ms |
5528 KB |
Output is correct |
56 |
Correct |
38 ms |
3160 KB |
Output is correct |
57 |
Correct |
28 ms |
3128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
50 ms |
2636 KB |
Output is correct |
10 |
Correct |
32 ms |
1880 KB |
Output is correct |
11 |
Correct |
25 ms |
1472 KB |
Output is correct |
12 |
Correct |
24 ms |
1184 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
452 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
34 ms |
6152 KB |
Output is correct |
22 |
Correct |
124 ms |
11460 KB |
Output is correct |
23 |
Correct |
105 ms |
10816 KB |
Output is correct |
24 |
Correct |
33 ms |
1876 KB |
Output is correct |
25 |
Correct |
78 ms |
5028 KB |
Output is correct |
26 |
Correct |
13 ms |
1452 KB |
Output is correct |
27 |
Correct |
98 ms |
10708 KB |
Output is correct |
28 |
Correct |
109 ms |
10808 KB |
Output is correct |
29 |
Correct |
121 ms |
10736 KB |
Output is correct |
30 |
Correct |
137 ms |
10816 KB |
Output is correct |
31 |
Correct |
228 ms |
10812 KB |
Output is correct |
32 |
Correct |
123 ms |
6188 KB |
Output is correct |
33 |
Correct |
255 ms |
11468 KB |
Output is correct |
34 |
Correct |
232 ms |
6088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
95 ms |
5096 KB |
Output is correct |
12 |
Correct |
100 ms |
10836 KB |
Output is correct |
13 |
Correct |
105 ms |
8924 KB |
Output is correct |
14 |
Correct |
100 ms |
8776 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
50 ms |
2636 KB |
Output is correct |
24 |
Correct |
32 ms |
1880 KB |
Output is correct |
25 |
Correct |
25 ms |
1472 KB |
Output is correct |
26 |
Correct |
24 ms |
1184 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
452 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
3 ms |
468 KB |
Output is correct |
42 |
Correct |
4 ms |
596 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
22 ms |
2116 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
3 ms |
444 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
52 ms |
5528 KB |
Output is correct |
52 |
Correct |
38 ms |
3160 KB |
Output is correct |
53 |
Correct |
28 ms |
3128 KB |
Output is correct |
54 |
Correct |
33 ms |
1876 KB |
Output is correct |
55 |
Correct |
78 ms |
5028 KB |
Output is correct |
56 |
Correct |
13 ms |
1452 KB |
Output is correct |
57 |
Correct |
98 ms |
10708 KB |
Output is correct |
58 |
Correct |
109 ms |
10808 KB |
Output is correct |
59 |
Correct |
121 ms |
10736 KB |
Output is correct |
60 |
Correct |
137 ms |
10816 KB |
Output is correct |
61 |
Correct |
228 ms |
10812 KB |
Output is correct |
62 |
Correct |
123 ms |
6188 KB |
Output is correct |
63 |
Correct |
255 ms |
11468 KB |
Output is correct |
64 |
Correct |
232 ms |
6088 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
34 ms |
6152 KB |
Output is correct |
67 |
Correct |
124 ms |
11460 KB |
Output is correct |
68 |
Correct |
105 ms |
10816 KB |
Output is correct |
69 |
Correct |
22 ms |
1356 KB |
Output is correct |
70 |
Correct |
7 ms |
592 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
35 ms |
1776 KB |
Output is correct |
73 |
Correct |
7 ms |
596 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
123 ms |
10820 KB |
Output is correct |
76 |
Correct |
121 ms |
10700 KB |
Output is correct |
77 |
Correct |
132 ms |
10768 KB |
Output is correct |
78 |
Correct |
166 ms |
10896 KB |
Output is correct |
79 |
Correct |
219 ms |
10880 KB |
Output is correct |
80 |
Correct |
253 ms |
10744 KB |
Output is correct |
81 |
Correct |
236 ms |
8832 KB |
Output is correct |
82 |
Correct |
226 ms |
8828 KB |
Output is correct |