#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
vector<ll> a,b;
bool isok(ll target){ // ans>=target;
ll time = 0;
for (ll i = 0;i<n;i++){
ll x = m;
ll t = target - x*a[i];
if (t<=-a[i]){
x -= (-t)/a[i];
t = target - x*a[i];
}else if (t>0){
x += t/b[i];
t -= (t/b[i])*b[i];
while (t>0){
x++;
t-=b[i];
}
}
time += x;
if (time>n*m) return false;
}
return true;
}
ll check(ll l, ll r){
if (l >= r) return l;
ll mid = (l+r)/2;
if (isok(mid+1)){
return check(mid+1,r);
}else{
return check(l,mid);
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin >> n >> m;
a.resize(n,0);
b.resize(n,0);
for (ll i = 0;i<n;i++){
cin >> a[i];
}
for (ll i = 0;i<n;i++){
cin >> b[i];
a[i] = max(a[i], b[i]);
}
cout << check(0,5e18) << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
70 ms |
5600 KB |
Output is correct |
12 |
Correct |
73 ms |
5384 KB |
Output is correct |
13 |
Correct |
68 ms |
5124 KB |
Output is correct |
14 |
Correct |
62 ms |
4940 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
31 ms |
5780 KB |
Output is correct |
17 |
Correct |
102 ms |
6608 KB |
Output is correct |
18 |
Correct |
68 ms |
6608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
31 ms |
5780 KB |
Output is correct |
3 |
Correct |
102 ms |
6608 KB |
Output is correct |
4 |
Correct |
68 ms |
6608 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 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 |
53 ms |
2684 KB |
Output is correct |
14 |
Correct |
45 ms |
1868 KB |
Output is correct |
15 |
Correct |
26 ms |
1504 KB |
Output is correct |
16 |
Correct |
21 ms |
1228 KB |
Output is correct |
17 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
70 ms |
5600 KB |
Output is correct |
12 |
Correct |
73 ms |
5384 KB |
Output is correct |
13 |
Correct |
68 ms |
5124 KB |
Output is correct |
14 |
Correct |
62 ms |
4940 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 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 |
53 ms |
2684 KB |
Output is correct |
24 |
Correct |
45 ms |
1868 KB |
Output is correct |
25 |
Correct |
26 ms |
1504 KB |
Output is correct |
26 |
Correct |
21 ms |
1228 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 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 |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
448 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
31 ms |
5780 KB |
Output is correct |
36 |
Correct |
102 ms |
6608 KB |
Output is correct |
37 |
Correct |
68 ms |
6608 KB |
Output is correct |
38 |
Correct |
1 ms |
312 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 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 |
308 KB |
Output is correct |
45 |
Correct |
3 ms |
460 KB |
Output is correct |
46 |
Correct |
11 ms |
580 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
21 ms |
1908 KB |
Output is correct |
49 |
Correct |
1 ms |
204 KB |
Output is correct |
50 |
Correct |
1 ms |
204 KB |
Output is correct |
51 |
Correct |
2 ms |
460 KB |
Output is correct |
52 |
Correct |
0 ms |
204 KB |
Output is correct |
53 |
Correct |
1 ms |
316 KB |
Output is correct |
54 |
Correct |
1 ms |
332 KB |
Output is correct |
55 |
Correct |
56 ms |
3384 KB |
Output is correct |
56 |
Correct |
36 ms |
2504 KB |
Output is correct |
57 |
Correct |
21 ms |
2500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 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 |
53 ms |
2684 KB |
Output is correct |
10 |
Correct |
45 ms |
1868 KB |
Output is correct |
11 |
Correct |
26 ms |
1504 KB |
Output is correct |
12 |
Correct |
21 ms |
1228 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 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 |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
448 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
31 ms |
5780 KB |
Output is correct |
22 |
Correct |
102 ms |
6608 KB |
Output is correct |
23 |
Correct |
68 ms |
6608 KB |
Output is correct |
24 |
Correct |
34 ms |
1596 KB |
Output is correct |
25 |
Correct |
79 ms |
3616 KB |
Output is correct |
26 |
Correct |
14 ms |
1248 KB |
Output is correct |
27 |
Correct |
102 ms |
6848 KB |
Output is correct |
28 |
Correct |
112 ms |
6868 KB |
Output is correct |
29 |
Correct |
111 ms |
6724 KB |
Output is correct |
30 |
Correct |
137 ms |
6876 KB |
Output is correct |
31 |
Correct |
222 ms |
6832 KB |
Output is correct |
32 |
Correct |
125 ms |
5768 KB |
Output is correct |
33 |
Correct |
176 ms |
6840 KB |
Output is correct |
34 |
Correct |
97 ms |
5516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
70 ms |
5600 KB |
Output is correct |
12 |
Correct |
73 ms |
5384 KB |
Output is correct |
13 |
Correct |
68 ms |
5124 KB |
Output is correct |
14 |
Correct |
62 ms |
4940 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 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 |
53 ms |
2684 KB |
Output is correct |
24 |
Correct |
45 ms |
1868 KB |
Output is correct |
25 |
Correct |
26 ms |
1504 KB |
Output is correct |
26 |
Correct |
21 ms |
1228 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 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 |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
448 KB |
Output is correct |
34 |
Correct |
1 ms |
312 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 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 |
308 KB |
Output is correct |
41 |
Correct |
3 ms |
460 KB |
Output is correct |
42 |
Correct |
11 ms |
580 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
21 ms |
1908 KB |
Output is correct |
45 |
Correct |
1 ms |
204 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
2 ms |
460 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
1 ms |
316 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
56 ms |
3384 KB |
Output is correct |
52 |
Correct |
36 ms |
2504 KB |
Output is correct |
53 |
Correct |
21 ms |
2500 KB |
Output is correct |
54 |
Correct |
34 ms |
1596 KB |
Output is correct |
55 |
Correct |
79 ms |
3616 KB |
Output is correct |
56 |
Correct |
14 ms |
1248 KB |
Output is correct |
57 |
Correct |
102 ms |
6848 KB |
Output is correct |
58 |
Correct |
112 ms |
6868 KB |
Output is correct |
59 |
Correct |
111 ms |
6724 KB |
Output is correct |
60 |
Correct |
137 ms |
6876 KB |
Output is correct |
61 |
Correct |
222 ms |
6832 KB |
Output is correct |
62 |
Correct |
125 ms |
5768 KB |
Output is correct |
63 |
Correct |
176 ms |
6840 KB |
Output is correct |
64 |
Correct |
97 ms |
5516 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
31 ms |
5780 KB |
Output is correct |
67 |
Correct |
102 ms |
6608 KB |
Output is correct |
68 |
Correct |
68 ms |
6608 KB |
Output is correct |
69 |
Correct |
21 ms |
1228 KB |
Output is correct |
70 |
Correct |
6 ms |
588 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
40 ms |
1456 KB |
Output is correct |
73 |
Correct |
8 ms |
632 KB |
Output is correct |
74 |
Correct |
1 ms |
324 KB |
Output is correct |
75 |
Correct |
104 ms |
6028 KB |
Output is correct |
76 |
Correct |
126 ms |
6084 KB |
Output is correct |
77 |
Correct |
135 ms |
6108 KB |
Output is correct |
78 |
Correct |
174 ms |
6020 KB |
Output is correct |
79 |
Correct |
232 ms |
6116 KB |
Output is correct |
80 |
Correct |
250 ms |
6120 KB |
Output is correct |
81 |
Correct |
146 ms |
6032 KB |
Output is correct |
82 |
Correct |
130 ms |
6076 KB |
Output is correct |