#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=3e5+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
ll n,m;
ll a[MAX],b[MAX];
bool ok(ll low) {
ll need=0;
for (int i=1;i<=n;i++) {
ll org=max(a[i],b[i])*m;
if (org>=low) need-=(org-low)/max(a[i],b[i]);
else need+=(low-org-1)/b[i]+1;
if (need>oo) return false;
if (need<-oo) return true;
}
// cout<<need<<"\n";
return (need<=0);
}
int main() {
speed;
cin>>n>>m;
for (int i=1;i<=n;i++) {
cin>>a[i];
}
for (int i=1;i<=n;i++) {
cin>>b[i];
}
ll l=1,r=1e16;
while (l<r) {
ll mid=(l+r+1)/2;
// cout<<l<<" "<<mid<<" "<<r<<"\n";
if (ok(mid)) l=mid;
else r=mid-1;
}
cout<<l<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2512 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2408 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
126 ms |
5136 KB |
Output is correct |
12 |
Correct |
126 ms |
5128 KB |
Output is correct |
13 |
Correct |
117 ms |
5132 KB |
Output is correct |
14 |
Correct |
127 ms |
5132 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
128 ms |
5204 KB |
Output is correct |
17 |
Correct |
128 ms |
4944 KB |
Output is correct |
18 |
Correct |
127 ms |
5140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
128 ms |
5204 KB |
Output is correct |
3 |
Correct |
128 ms |
4944 KB |
Output is correct |
4 |
Correct |
127 ms |
5140 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
66 ms |
4564 KB |
Output is correct |
14 |
Correct |
43 ms |
4696 KB |
Output is correct |
15 |
Correct |
32 ms |
4700 KB |
Output is correct |
16 |
Correct |
27 ms |
4876 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
3 ms |
2396 KB |
Output is correct |
23 |
Correct |
3 ms |
2556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2512 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2408 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
126 ms |
5136 KB |
Output is correct |
12 |
Correct |
126 ms |
5128 KB |
Output is correct |
13 |
Correct |
117 ms |
5132 KB |
Output is correct |
14 |
Correct |
127 ms |
5132 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
66 ms |
4564 KB |
Output is correct |
24 |
Correct |
43 ms |
4696 KB |
Output is correct |
25 |
Correct |
32 ms |
4700 KB |
Output is correct |
26 |
Correct |
27 ms |
4876 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
3 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2556 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
128 ms |
5204 KB |
Output is correct |
36 |
Correct |
128 ms |
4944 KB |
Output is correct |
37 |
Correct |
127 ms |
5140 KB |
Output is correct |
38 |
Correct |
1 ms |
2392 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
3 ms |
2396 KB |
Output is correct |
46 |
Correct |
4 ms |
2392 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
22 ms |
4748 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
3 ms |
2396 KB |
Output is correct |
52 |
Correct |
0 ms |
2396 KB |
Output is correct |
53 |
Correct |
0 ms |
2396 KB |
Output is correct |
54 |
Correct |
1 ms |
2648 KB |
Output is correct |
55 |
Correct |
63 ms |
4724 KB |
Output is correct |
56 |
Correct |
39 ms |
4700 KB |
Output is correct |
57 |
Correct |
45 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
66 ms |
4564 KB |
Output is correct |
10 |
Correct |
43 ms |
4696 KB |
Output is correct |
11 |
Correct |
32 ms |
4700 KB |
Output is correct |
12 |
Correct |
27 ms |
4876 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
3 ms |
2396 KB |
Output is correct |
19 |
Correct |
3 ms |
2556 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
128 ms |
5204 KB |
Output is correct |
22 |
Correct |
128 ms |
4944 KB |
Output is correct |
23 |
Correct |
127 ms |
5140 KB |
Output is correct |
24 |
Correct |
27 ms |
4952 KB |
Output is correct |
25 |
Correct |
72 ms |
7332 KB |
Output is correct |
26 |
Correct |
15 ms |
5208 KB |
Output is correct |
27 |
Correct |
130 ms |
10832 KB |
Output is correct |
28 |
Correct |
132 ms |
10884 KB |
Output is correct |
29 |
Correct |
131 ms |
10948 KB |
Output is correct |
30 |
Correct |
141 ms |
10836 KB |
Output is correct |
31 |
Incorrect |
188 ms |
10940 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2512 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2408 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
126 ms |
5136 KB |
Output is correct |
12 |
Correct |
126 ms |
5128 KB |
Output is correct |
13 |
Correct |
117 ms |
5132 KB |
Output is correct |
14 |
Correct |
127 ms |
5132 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
66 ms |
4564 KB |
Output is correct |
24 |
Correct |
43 ms |
4696 KB |
Output is correct |
25 |
Correct |
32 ms |
4700 KB |
Output is correct |
26 |
Correct |
27 ms |
4876 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
3 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2556 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
0 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
3 ms |
2396 KB |
Output is correct |
42 |
Correct |
4 ms |
2392 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
22 ms |
4748 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
3 ms |
2396 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
0 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2648 KB |
Output is correct |
51 |
Correct |
63 ms |
4724 KB |
Output is correct |
52 |
Correct |
39 ms |
4700 KB |
Output is correct |
53 |
Correct |
45 ms |
4696 KB |
Output is correct |
54 |
Correct |
27 ms |
4952 KB |
Output is correct |
55 |
Correct |
72 ms |
7332 KB |
Output is correct |
56 |
Correct |
15 ms |
5208 KB |
Output is correct |
57 |
Correct |
130 ms |
10832 KB |
Output is correct |
58 |
Correct |
132 ms |
10884 KB |
Output is correct |
59 |
Correct |
131 ms |
10948 KB |
Output is correct |
60 |
Correct |
141 ms |
10836 KB |
Output is correct |
61 |
Incorrect |
188 ms |
10940 KB |
Output isn't correct |
62 |
Halted |
0 ms |
0 KB |
- |