#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
int n,a[300005],b[300005],i,ans,l,r,w,m,sum;
cin>>n>>m;
for (i=1;i<n+1;i++) cin>>a[i];
for (i=1;i<n+1;i++) cin>>b[i];
ans=0;l=0;r=1e18;
while (l<=r)
{
w=(l+r)/2;
bool tr=true;
sum=0;
for (i=1;i<n+1;i++)
{
if (a[i]>b[i])
{
if (a[i]*m>=w) sum += w/a[i] + (w%a[i]!=0);
else sum += m + (w-a[i]*m)/b[i] + ((w-a[i]*m)%b[i]!=0);
}
else sum += w/b[i] + (w%b[i]!=0);
if (sum>n*m) tr=false;
}
if (tr)
{
ans=w;l=w+1;
}
else r=w-1;
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
168 ms |
4988 KB |
Output is correct |
12 |
Correct |
180 ms |
4996 KB |
Output is correct |
13 |
Correct |
154 ms |
4992 KB |
Output is correct |
14 |
Correct |
226 ms |
4996 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
191 ms |
6164 KB |
Output is correct |
17 |
Correct |
185 ms |
11424 KB |
Output is correct |
18 |
Correct |
163 ms |
10792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
191 ms |
6164 KB |
Output is correct |
3 |
Correct |
185 ms |
11424 KB |
Output is correct |
4 |
Correct |
163 ms |
10792 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4972 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
80 ms |
4992 KB |
Output is correct |
14 |
Correct |
55 ms |
4948 KB |
Output is correct |
15 |
Correct |
41 ms |
4988 KB |
Output is correct |
16 |
Correct |
34 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
6 ms |
5012 KB |
Output is correct |
23 |
Correct |
6 ms |
5076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
168 ms |
4988 KB |
Output is correct |
12 |
Correct |
180 ms |
4996 KB |
Output is correct |
13 |
Correct |
154 ms |
4992 KB |
Output is correct |
14 |
Correct |
226 ms |
4996 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4972 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
80 ms |
4992 KB |
Output is correct |
24 |
Correct |
55 ms |
4948 KB |
Output is correct |
25 |
Correct |
41 ms |
4988 KB |
Output is correct |
26 |
Correct |
34 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
2 ms |
4948 KB |
Output is correct |
30 |
Correct |
2 ms |
4948 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
6 ms |
5012 KB |
Output is correct |
33 |
Correct |
6 ms |
5076 KB |
Output is correct |
34 |
Correct |
2 ms |
4948 KB |
Output is correct |
35 |
Correct |
191 ms |
6164 KB |
Output is correct |
36 |
Correct |
185 ms |
11424 KB |
Output is correct |
37 |
Correct |
163 ms |
10792 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
2 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
2 ms |
4948 KB |
Output is correct |
42 |
Correct |
2 ms |
4948 KB |
Output is correct |
43 |
Correct |
2 ms |
4948 KB |
Output is correct |
44 |
Correct |
2 ms |
4948 KB |
Output is correct |
45 |
Correct |
5 ms |
5076 KB |
Output is correct |
46 |
Correct |
7 ms |
5076 KB |
Output is correct |
47 |
Correct |
4 ms |
4948 KB |
Output is correct |
48 |
Correct |
31 ms |
5884 KB |
Output is correct |
49 |
Correct |
2 ms |
4948 KB |
Output is correct |
50 |
Correct |
2 ms |
4948 KB |
Output is correct |
51 |
Correct |
5 ms |
5076 KB |
Output is correct |
52 |
Correct |
2 ms |
4948 KB |
Output is correct |
53 |
Correct |
2 ms |
4932 KB |
Output is correct |
54 |
Correct |
3 ms |
4948 KB |
Output is correct |
55 |
Correct |
89 ms |
7860 KB |
Output is correct |
56 |
Correct |
58 ms |
6260 KB |
Output is correct |
57 |
Correct |
76 ms |
6144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4972 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
80 ms |
4992 KB |
Output is correct |
10 |
Correct |
55 ms |
4948 KB |
Output is correct |
11 |
Correct |
41 ms |
4988 KB |
Output is correct |
12 |
Correct |
34 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
6 ms |
5012 KB |
Output is correct |
19 |
Correct |
6 ms |
5076 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
191 ms |
6164 KB |
Output is correct |
22 |
Correct |
185 ms |
11424 KB |
Output is correct |
23 |
Correct |
163 ms |
10792 KB |
Output is correct |
24 |
Correct |
39 ms |
5888 KB |
Output is correct |
25 |
Correct |
88 ms |
7588 KB |
Output is correct |
26 |
Correct |
20 ms |
5508 KB |
Output is correct |
27 |
Correct |
164 ms |
10756 KB |
Output is correct |
28 |
Correct |
161 ms |
10788 KB |
Output is correct |
29 |
Correct |
178 ms |
10732 KB |
Output is correct |
30 |
Correct |
173 ms |
10736 KB |
Output is correct |
31 |
Correct |
222 ms |
10700 KB |
Output is correct |
32 |
Correct |
226 ms |
6092 KB |
Output is correct |
33 |
Correct |
250 ms |
11440 KB |
Output is correct |
34 |
Correct |
224 ms |
6160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
4 ms |
4948 KB |
Output is correct |
11 |
Correct |
168 ms |
4988 KB |
Output is correct |
12 |
Correct |
180 ms |
4996 KB |
Output is correct |
13 |
Correct |
154 ms |
4992 KB |
Output is correct |
14 |
Correct |
226 ms |
4996 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4972 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
2 ms |
4948 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
23 |
Correct |
80 ms |
4992 KB |
Output is correct |
24 |
Correct |
55 ms |
4948 KB |
Output is correct |
25 |
Correct |
41 ms |
4988 KB |
Output is correct |
26 |
Correct |
34 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
2 ms |
4948 KB |
Output is correct |
30 |
Correct |
2 ms |
4948 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
6 ms |
5012 KB |
Output is correct |
33 |
Correct |
6 ms |
5076 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
2 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
2 ms |
4948 KB |
Output is correct |
38 |
Correct |
2 ms |
4948 KB |
Output is correct |
39 |
Correct |
2 ms |
4948 KB |
Output is correct |
40 |
Correct |
2 ms |
4948 KB |
Output is correct |
41 |
Correct |
5 ms |
5076 KB |
Output is correct |
42 |
Correct |
7 ms |
5076 KB |
Output is correct |
43 |
Correct |
4 ms |
4948 KB |
Output is correct |
44 |
Correct |
31 ms |
5884 KB |
Output is correct |
45 |
Correct |
2 ms |
4948 KB |
Output is correct |
46 |
Correct |
2 ms |
4948 KB |
Output is correct |
47 |
Correct |
5 ms |
5076 KB |
Output is correct |
48 |
Correct |
2 ms |
4948 KB |
Output is correct |
49 |
Correct |
2 ms |
4932 KB |
Output is correct |
50 |
Correct |
3 ms |
4948 KB |
Output is correct |
51 |
Correct |
89 ms |
7860 KB |
Output is correct |
52 |
Correct |
58 ms |
6260 KB |
Output is correct |
53 |
Correct |
76 ms |
6144 KB |
Output is correct |
54 |
Correct |
39 ms |
5888 KB |
Output is correct |
55 |
Correct |
88 ms |
7588 KB |
Output is correct |
56 |
Correct |
20 ms |
5508 KB |
Output is correct |
57 |
Correct |
164 ms |
10756 KB |
Output is correct |
58 |
Correct |
161 ms |
10788 KB |
Output is correct |
59 |
Correct |
178 ms |
10732 KB |
Output is correct |
60 |
Correct |
173 ms |
10736 KB |
Output is correct |
61 |
Correct |
222 ms |
10700 KB |
Output is correct |
62 |
Correct |
226 ms |
6092 KB |
Output is correct |
63 |
Correct |
250 ms |
11440 KB |
Output is correct |
64 |
Correct |
224 ms |
6160 KB |
Output is correct |
65 |
Correct |
2 ms |
4948 KB |
Output is correct |
66 |
Correct |
191 ms |
6164 KB |
Output is correct |
67 |
Correct |
185 ms |
11424 KB |
Output is correct |
68 |
Correct |
163 ms |
10792 KB |
Output is correct |
69 |
Correct |
26 ms |
5588 KB |
Output is correct |
70 |
Correct |
8 ms |
5160 KB |
Output is correct |
71 |
Correct |
2 ms |
5076 KB |
Output is correct |
72 |
Correct |
34 ms |
5828 KB |
Output is correct |
73 |
Correct |
9 ms |
5124 KB |
Output is correct |
74 |
Correct |
3 ms |
5028 KB |
Output is correct |
75 |
Correct |
180 ms |
10744 KB |
Output is correct |
76 |
Correct |
175 ms |
10864 KB |
Output is correct |
77 |
Correct |
179 ms |
10752 KB |
Output is correct |
78 |
Correct |
198 ms |
10788 KB |
Output is correct |
79 |
Correct |
232 ms |
10732 KB |
Output is correct |
80 |
Correct |
222 ms |
10796 KB |
Output is correct |
81 |
Correct |
223 ms |
8812 KB |
Output is correct |
82 |
Correct |
238 ms |
8812 KB |
Output is correct |