#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define vl vector<ll>
#define sl set<ll>
#define pb push_back
#define all(v) v.begin(), v.end()
#define f first
#define s second
#define ld long double
using namespace std;
const int sz = 3e5+5;
ll n, m, i, j;
ll a[sz], b[sz];
bool check(ll mid)
{
ll need = 0;
for(i = 0; i < n; i++)
{
ll have = max(a[i], b[i]) * m, 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);
}
int main()
{
cin >> n >> m;
for(i = 0; i < n; i++) cin >> a[i];
for(i = 0; i < n; i++) cin >> b[i];
ll l = 1, r = 1e18, k = 0;
while(l <= r)
{
ll mid = (l + r) / 2;
if(check(mid))
{
k = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << k << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
253 ms |
9944 KB |
Output is correct |
12 |
Correct |
274 ms |
10036 KB |
Output is correct |
13 |
Correct |
199 ms |
8780 KB |
Output is correct |
14 |
Correct |
177 ms |
8868 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
80 ms |
6044 KB |
Output is correct |
17 |
Correct |
290 ms |
10060 KB |
Output is correct |
18 |
Correct |
264 ms |
10036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
80 ms |
6044 KB |
Output is correct |
3 |
Correct |
290 ms |
10060 KB |
Output is correct |
4 |
Correct |
264 ms |
10036 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
134 ms |
5548 KB |
Output is correct |
14 |
Correct |
87 ms |
3788 KB |
Output is correct |
15 |
Correct |
64 ms |
2828 KB |
Output is correct |
16 |
Correct |
52 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
6 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
253 ms |
9944 KB |
Output is correct |
12 |
Correct |
274 ms |
10036 KB |
Output is correct |
13 |
Correct |
199 ms |
8780 KB |
Output is correct |
14 |
Correct |
177 ms |
8868 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
134 ms |
5548 KB |
Output is correct |
24 |
Correct |
87 ms |
3788 KB |
Output is correct |
25 |
Correct |
64 ms |
2828 KB |
Output is correct |
26 |
Correct |
52 ms |
2392 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
80 ms |
6044 KB |
Output is correct |
36 |
Correct |
290 ms |
10060 KB |
Output is correct |
37 |
Correct |
264 ms |
10036 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
6 ms |
496 KB |
Output is correct |
46 |
Correct |
10 ms |
568 KB |
Output is correct |
47 |
Correct |
2 ms |
340 KB |
Output is correct |
48 |
Correct |
47 ms |
2016 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
5 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
137 ms |
5444 KB |
Output is correct |
56 |
Correct |
76 ms |
3136 KB |
Output is correct |
57 |
Correct |
65 ms |
3124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
134 ms |
5548 KB |
Output is correct |
10 |
Correct |
87 ms |
3788 KB |
Output is correct |
11 |
Correct |
64 ms |
2828 KB |
Output is correct |
12 |
Correct |
52 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
6 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
80 ms |
6044 KB |
Output is correct |
22 |
Correct |
290 ms |
10060 KB |
Output is correct |
23 |
Correct |
264 ms |
10036 KB |
Output is correct |
24 |
Correct |
71 ms |
1884 KB |
Output is correct |
25 |
Correct |
161 ms |
4988 KB |
Output is correct |
26 |
Correct |
32 ms |
1392 KB |
Output is correct |
27 |
Correct |
261 ms |
10924 KB |
Output is correct |
28 |
Correct |
278 ms |
10772 KB |
Output is correct |
29 |
Correct |
274 ms |
10696 KB |
Output is correct |
30 |
Correct |
302 ms |
10736 KB |
Output is correct |
31 |
Correct |
370 ms |
10768 KB |
Output is correct |
32 |
Correct |
181 ms |
6144 KB |
Output is correct |
33 |
Correct |
408 ms |
11312 KB |
Output is correct |
34 |
Correct |
180 ms |
6064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
253 ms |
9944 KB |
Output is correct |
12 |
Correct |
274 ms |
10036 KB |
Output is correct |
13 |
Correct |
199 ms |
8780 KB |
Output is correct |
14 |
Correct |
177 ms |
8868 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
134 ms |
5548 KB |
Output is correct |
24 |
Correct |
87 ms |
3788 KB |
Output is correct |
25 |
Correct |
64 ms |
2828 KB |
Output is correct |
26 |
Correct |
52 ms |
2392 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
6 ms |
496 KB |
Output is correct |
42 |
Correct |
10 ms |
568 KB |
Output is correct |
43 |
Correct |
2 ms |
340 KB |
Output is correct |
44 |
Correct |
47 ms |
2016 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
5 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
137 ms |
5444 KB |
Output is correct |
52 |
Correct |
76 ms |
3136 KB |
Output is correct |
53 |
Correct |
65 ms |
3124 KB |
Output is correct |
54 |
Correct |
71 ms |
1884 KB |
Output is correct |
55 |
Correct |
161 ms |
4988 KB |
Output is correct |
56 |
Correct |
32 ms |
1392 KB |
Output is correct |
57 |
Correct |
261 ms |
10924 KB |
Output is correct |
58 |
Correct |
278 ms |
10772 KB |
Output is correct |
59 |
Correct |
274 ms |
10696 KB |
Output is correct |
60 |
Correct |
302 ms |
10736 KB |
Output is correct |
61 |
Correct |
370 ms |
10768 KB |
Output is correct |
62 |
Correct |
181 ms |
6144 KB |
Output is correct |
63 |
Correct |
408 ms |
11312 KB |
Output is correct |
64 |
Correct |
180 ms |
6064 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
80 ms |
6044 KB |
Output is correct |
67 |
Correct |
290 ms |
10060 KB |
Output is correct |
68 |
Correct |
264 ms |
10036 KB |
Output is correct |
69 |
Correct |
39 ms |
1364 KB |
Output is correct |
70 |
Correct |
10 ms |
468 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
59 ms |
1800 KB |
Output is correct |
73 |
Correct |
12 ms |
656 KB |
Output is correct |
74 |
Correct |
2 ms |
320 KB |
Output is correct |
75 |
Correct |
257 ms |
10788 KB |
Output is correct |
76 |
Correct |
316 ms |
10716 KB |
Output is correct |
77 |
Correct |
279 ms |
10768 KB |
Output is correct |
78 |
Correct |
332 ms |
10772 KB |
Output is correct |
79 |
Correct |
377 ms |
10768 KB |
Output is correct |
80 |
Correct |
391 ms |
10700 KB |
Output is correct |
81 |
Correct |
324 ms |
8780 KB |
Output is correct |
82 |
Correct |
343 ms |
8908 KB |
Output is correct |