#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std ;
const ll N = 3e5 ;
ll n, m, l = 0, r = (1ll << 62ll), a[N + 1], b[N + 1], now[N + 1] ;
signed main()
{
ios_base::sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
cout.tie( 0 ) ;
cin >> n >> m ;
for(ll i = 1 ; i <= n ; i++)
cin >> a[i] ;
for(ll i = 1 ; i <= n ; i++)
cin >> b[i] ;
while(l + 1 < r)
{
bool flag = 0 ;
ll mid = (l + r) >> 1, cnt = 0 ;
for(ll i = 1 ; i <= n ; i++)
{
now[i] = 0 ;
if(a[i] > b[i])
{
if(((mid + a[i] - 1) / a[i]) < m)
{
now[i] = ((mid + a[i] - 1) / a[i]) * a[i] ;
cnt += ((mid + a[i] - 1) / a[i]) ;
}
else
{
now[i] = m * a[i] ;
cnt += m ;
}
}
}
for(ll i = 1 ; i <= n ; i++)
{
if(now[i] >= mid)
continue ;
cnt += (mid - now[i] + b[i] - 1) / b[i] ;
if(cnt < 0 || (mid - now[i] + b[i] - 1) / b[i] < 0)
flag = 1 ;
}
if(cnt > n * m || flag)
r = mid ;
else
l = mid ;
}
cout << l ;
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
246 ms |
7348 KB |
Output is correct |
12 |
Correct |
240 ms |
7348 KB |
Output is correct |
13 |
Correct |
150 ms |
7344 KB |
Output is correct |
14 |
Correct |
283 ms |
7348 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
200 ms |
7344 KB |
Output is correct |
17 |
Correct |
160 ms |
7352 KB |
Output is correct |
18 |
Correct |
161 ms |
7348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
200 ms |
7344 KB |
Output is correct |
3 |
Correct |
160 ms |
7352 KB |
Output is correct |
4 |
Correct |
161 ms |
7348 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
79 ms |
3844 KB |
Output is correct |
14 |
Correct |
54 ms |
2572 KB |
Output is correct |
15 |
Correct |
40 ms |
2004 KB |
Output is correct |
16 |
Correct |
32 ms |
1660 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 |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
246 ms |
7348 KB |
Output is correct |
12 |
Correct |
240 ms |
7348 KB |
Output is correct |
13 |
Correct |
150 ms |
7344 KB |
Output is correct |
14 |
Correct |
283 ms |
7348 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 |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
79 ms |
3844 KB |
Output is correct |
24 |
Correct |
54 ms |
2572 KB |
Output is correct |
25 |
Correct |
40 ms |
2004 KB |
Output is correct |
26 |
Correct |
32 ms |
1660 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 |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
452 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
200 ms |
7344 KB |
Output is correct |
36 |
Correct |
160 ms |
7352 KB |
Output is correct |
37 |
Correct |
161 ms |
7348 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
4 ms |
340 KB |
Output is correct |
46 |
Correct |
7 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
44 ms |
1528 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
4 ms |
340 KB |
Output is correct |
52 |
Correct |
0 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Correct |
0 ms |
340 KB |
Output is correct |
55 |
Correct |
124 ms |
3808 KB |
Output is correct |
56 |
Correct |
50 ms |
2680 KB |
Output is correct |
57 |
Correct |
96 ms |
2668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 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 |
212 KB |
Output is correct |
9 |
Correct |
79 ms |
3844 KB |
Output is correct |
10 |
Correct |
54 ms |
2572 KB |
Output is correct |
11 |
Correct |
40 ms |
2004 KB |
Output is correct |
12 |
Correct |
32 ms |
1660 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 |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
452 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
200 ms |
7344 KB |
Output is correct |
22 |
Correct |
160 ms |
7352 KB |
Output is correct |
23 |
Correct |
161 ms |
7348 KB |
Output is correct |
24 |
Correct |
31 ms |
1404 KB |
Output is correct |
25 |
Correct |
83 ms |
3472 KB |
Output is correct |
26 |
Correct |
17 ms |
1080 KB |
Output is correct |
27 |
Correct |
160 ms |
7348 KB |
Output is correct |
28 |
Correct |
161 ms |
7344 KB |
Output is correct |
29 |
Correct |
160 ms |
7244 KB |
Output is correct |
30 |
Correct |
179 ms |
7352 KB |
Output is correct |
31 |
Correct |
208 ms |
7348 KB |
Output is correct |
32 |
Correct |
221 ms |
7344 KB |
Output is correct |
33 |
Correct |
225 ms |
7352 KB |
Output is correct |
34 |
Correct |
221 ms |
7348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
246 ms |
7348 KB |
Output is correct |
12 |
Correct |
240 ms |
7348 KB |
Output is correct |
13 |
Correct |
150 ms |
7344 KB |
Output is correct |
14 |
Correct |
283 ms |
7348 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 |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
79 ms |
3844 KB |
Output is correct |
24 |
Correct |
54 ms |
2572 KB |
Output is correct |
25 |
Correct |
40 ms |
2004 KB |
Output is correct |
26 |
Correct |
32 ms |
1660 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 |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
452 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
4 ms |
340 KB |
Output is correct |
42 |
Correct |
7 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
44 ms |
1528 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
4 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
0 ms |
340 KB |
Output is correct |
50 |
Correct |
0 ms |
340 KB |
Output is correct |
51 |
Correct |
124 ms |
3808 KB |
Output is correct |
52 |
Correct |
50 ms |
2680 KB |
Output is correct |
53 |
Correct |
96 ms |
2668 KB |
Output is correct |
54 |
Correct |
31 ms |
1404 KB |
Output is correct |
55 |
Correct |
83 ms |
3472 KB |
Output is correct |
56 |
Correct |
17 ms |
1080 KB |
Output is correct |
57 |
Correct |
160 ms |
7348 KB |
Output is correct |
58 |
Correct |
161 ms |
7344 KB |
Output is correct |
59 |
Correct |
160 ms |
7244 KB |
Output is correct |
60 |
Correct |
179 ms |
7352 KB |
Output is correct |
61 |
Correct |
208 ms |
7348 KB |
Output is correct |
62 |
Correct |
221 ms |
7344 KB |
Output is correct |
63 |
Correct |
225 ms |
7352 KB |
Output is correct |
64 |
Correct |
221 ms |
7348 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
200 ms |
7344 KB |
Output is correct |
67 |
Correct |
160 ms |
7352 KB |
Output is correct |
68 |
Correct |
161 ms |
7348 KB |
Output is correct |
69 |
Correct |
27 ms |
1084 KB |
Output is correct |
70 |
Correct |
7 ms |
468 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
36 ms |
1236 KB |
Output is correct |
73 |
Correct |
8 ms |
468 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
249 ms |
7348 KB |
Output is correct |
76 |
Correct |
254 ms |
7348 KB |
Output is correct |
77 |
Correct |
244 ms |
7352 KB |
Output is correct |
78 |
Correct |
257 ms |
7344 KB |
Output is correct |
79 |
Correct |
254 ms |
7348 KB |
Output is correct |
80 |
Correct |
246 ms |
7344 KB |
Output is correct |
81 |
Correct |
213 ms |
7344 KB |
Output is correct |
82 |
Correct |
301 ms |
7284 KB |
Output is correct |