#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define all(X) X.begin(),X.end()
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
setio();
int n,m;
cin>>n>>m;
vector<pair<__int128,__int128>>v;
for(int i=0;i<n;i++){
int a;
cin>>a;
v.pb({a,0});
}
for(int i=0;i<n;i++){
int a;
cin>>a;
v[i].S=a;
}
int l=0,r=2e18+10;
while(l<r){
int mm=l+r+1>>1;
__int128 left=n*m;
bool ok=1;
for(int i=0;i<n;i++){
if(v[i].F>=v[i].S){
if(v[i].F*m>=mm){
__int128 x=((__int128)mm-1)/v[i].F+1;
left-=x;
}
else{
__int128 cur=mm;
left-=m;
cur-=m*v[i].F;
__int128 x=((__int128)cur-1)/v[i].S+1;
left-=x;
}
}
else{
__int128 x=((__int128)mm-1)/v[i].S+1;
left-=x;
}
}
if(left>=0){
l=mm;
}
else{
r=mm-1;
}
}
cout<<(int)l<<'\n';
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:37:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
37 | int mm=l+r+1>>1;
| ~~~^~
Main.cpp:39:14: warning: unused variable 'ok' [-Wunused-variable]
39 | bool ok=1;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
207 ms |
17200 KB |
Output is correct |
12 |
Correct |
212 ms |
18960 KB |
Output is correct |
13 |
Correct |
141 ms |
18892 KB |
Output is correct |
14 |
Correct |
195 ms |
18892 KB |
Output is correct |
15 |
Correct |
1 ms |
756 KB |
Output is correct |
16 |
Correct |
192 ms |
18380 KB |
Output is correct |
17 |
Correct |
158 ms |
17084 KB |
Output is correct |
18 |
Correct |
164 ms |
18984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
756 KB |
Output is correct |
2 |
Correct |
192 ms |
18380 KB |
Output is correct |
3 |
Correct |
158 ms |
17084 KB |
Output is correct |
4 |
Correct |
164 ms |
18984 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
544 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
81 ms |
9936 KB |
Output is correct |
14 |
Correct |
54 ms |
6352 KB |
Output is correct |
15 |
Correct |
41 ms |
6352 KB |
Output is correct |
16 |
Correct |
33 ms |
2520 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
736 KB |
Output is correct |
23 |
Correct |
3 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
207 ms |
17200 KB |
Output is correct |
12 |
Correct |
212 ms |
18960 KB |
Output is correct |
13 |
Correct |
141 ms |
18892 KB |
Output is correct |
14 |
Correct |
195 ms |
18892 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
544 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
81 ms |
9936 KB |
Output is correct |
24 |
Correct |
54 ms |
6352 KB |
Output is correct |
25 |
Correct |
41 ms |
6352 KB |
Output is correct |
26 |
Correct |
33 ms |
2520 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
736 KB |
Output is correct |
33 |
Correct |
3 ms |
736 KB |
Output is correct |
34 |
Correct |
1 ms |
756 KB |
Output is correct |
35 |
Correct |
192 ms |
18380 KB |
Output is correct |
36 |
Correct |
158 ms |
17084 KB |
Output is correct |
37 |
Correct |
164 ms |
18984 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
4 ms |
736 KB |
Output is correct |
46 |
Correct |
7 ms |
992 KB |
Output is correct |
47 |
Correct |
1 ms |
344 KB |
Output is correct |
48 |
Correct |
37 ms |
2520 KB |
Output is correct |
49 |
Correct |
0 ms |
344 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
4 ms |
736 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
106 ms |
9676 KB |
Output is correct |
56 |
Correct |
48 ms |
5076 KB |
Output is correct |
57 |
Correct |
65 ms |
6100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
544 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
81 ms |
9936 KB |
Output is correct |
10 |
Correct |
54 ms |
6352 KB |
Output is correct |
11 |
Correct |
41 ms |
6352 KB |
Output is correct |
12 |
Correct |
33 ms |
2520 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
736 KB |
Output is correct |
19 |
Correct |
3 ms |
736 KB |
Output is correct |
20 |
Correct |
1 ms |
756 KB |
Output is correct |
21 |
Correct |
192 ms |
18380 KB |
Output is correct |
22 |
Correct |
158 ms |
17084 KB |
Output is correct |
23 |
Correct |
164 ms |
18984 KB |
Output is correct |
24 |
Correct |
30 ms |
2520 KB |
Output is correct |
25 |
Correct |
81 ms |
8656 KB |
Output is correct |
26 |
Correct |
18 ms |
1500 KB |
Output is correct |
27 |
Correct |
159 ms |
17868 KB |
Output is correct |
28 |
Correct |
167 ms |
18884 KB |
Output is correct |
29 |
Correct |
170 ms |
18104 KB |
Output is correct |
30 |
Correct |
171 ms |
17824 KB |
Output is correct |
31 |
Correct |
202 ms |
18124 KB |
Output is correct |
32 |
Correct |
201 ms |
18112 KB |
Output is correct |
33 |
Correct |
170 ms |
21984 KB |
Output is correct |
34 |
Correct |
198 ms |
18892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
736 KB |
Output is correct |
11 |
Correct |
207 ms |
17200 KB |
Output is correct |
12 |
Correct |
212 ms |
18960 KB |
Output is correct |
13 |
Correct |
141 ms |
18892 KB |
Output is correct |
14 |
Correct |
195 ms |
18892 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
544 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
81 ms |
9936 KB |
Output is correct |
24 |
Correct |
54 ms |
6352 KB |
Output is correct |
25 |
Correct |
41 ms |
6352 KB |
Output is correct |
26 |
Correct |
33 ms |
2520 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
736 KB |
Output is correct |
33 |
Correct |
3 ms |
736 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
4 ms |
736 KB |
Output is correct |
42 |
Correct |
7 ms |
992 KB |
Output is correct |
43 |
Correct |
1 ms |
344 KB |
Output is correct |
44 |
Correct |
37 ms |
2520 KB |
Output is correct |
45 |
Correct |
0 ms |
344 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
4 ms |
736 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
106 ms |
9676 KB |
Output is correct |
52 |
Correct |
48 ms |
5076 KB |
Output is correct |
53 |
Correct |
65 ms |
6100 KB |
Output is correct |
54 |
Correct |
30 ms |
2520 KB |
Output is correct |
55 |
Correct |
81 ms |
8656 KB |
Output is correct |
56 |
Correct |
18 ms |
1500 KB |
Output is correct |
57 |
Correct |
159 ms |
17868 KB |
Output is correct |
58 |
Correct |
167 ms |
18884 KB |
Output is correct |
59 |
Correct |
170 ms |
18104 KB |
Output is correct |
60 |
Correct |
171 ms |
17824 KB |
Output is correct |
61 |
Correct |
202 ms |
18124 KB |
Output is correct |
62 |
Correct |
201 ms |
18112 KB |
Output is correct |
63 |
Correct |
170 ms |
21984 KB |
Output is correct |
64 |
Correct |
198 ms |
18892 KB |
Output is correct |
65 |
Correct |
1 ms |
756 KB |
Output is correct |
66 |
Correct |
192 ms |
18380 KB |
Output is correct |
67 |
Correct |
158 ms |
17084 KB |
Output is correct |
68 |
Correct |
164 ms |
18984 KB |
Output is correct |
69 |
Correct |
24 ms |
2008 KB |
Output is correct |
70 |
Correct |
6 ms |
988 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
33 ms |
3128 KB |
Output is correct |
73 |
Correct |
11 ms |
1484 KB |
Output is correct |
74 |
Correct |
1 ms |
348 KB |
Output is correct |
75 |
Correct |
218 ms |
21444 KB |
Output is correct |
76 |
Correct |
219 ms |
20352 KB |
Output is correct |
77 |
Correct |
222 ms |
19768 KB |
Output is correct |
78 |
Correct |
221 ms |
21436 KB |
Output is correct |
79 |
Correct |
221 ms |
20416 KB |
Output is correct |
80 |
Correct |
228 ms |
19644 KB |
Output is correct |
81 |
Correct |
208 ms |
17908 KB |
Output is correct |
82 |
Correct |
203 ms |
21828 KB |
Output is correct |