#include<iostream>
using namespace std;
#define int long long
long long a[1000000],b[1000000];
long long n,m;
bool ok(long long ile)
{
//cout<<"check "<<ile<<"\n";
long long biore=0;
for(int i=1;i<=n;i++)
{
if(a[i]>b[i])
{
long long ile_kursow_ja=ile/a[i];
if(ile%a[i]!=0)
ile_kursow_ja++;
if(ile_kursow_ja<=m)
{
biore+=ile_kursow_ja;
continue;
}
else{
biore+=m;
long long reszta=ile-m*a[i];
if(reszta<0)
continue;
long long dod=reszta/b[i];
if(reszta%b[i]!=0)
dod++;
biore+=dod;
continue;
}
}
long long ile_kursow=ile/b[i];
if(ile%b[i]!=0)
ile_kursow++;
biore+=ile_kursow;
//cout<<ile_kursow_ja<<" "<<wolne<<"\n";
}
if(biore<=n*m)
return 1;
else return 0;
}
int32_t main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i];
long long pocz=0,kon=3*1e18+1,sre,ostd=0;
//cout<<pocz<<" "<<kon<<"\n";
while(pocz<kon)
{
sre=(pocz+kon)/2;
//cout<<sre<<": "<<ok(sre)<<"\n";
if(ok(sre))
{
ostd=sre;
pocz=sre+1;
}
else kon=sre;
}
cout<<ostd;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
200 ms |
5008 KB |
Output is correct |
12 |
Correct |
201 ms |
4940 KB |
Output is correct |
13 |
Correct |
157 ms |
5016 KB |
Output is correct |
14 |
Incorrect |
496 ms |
5012 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
84 ms |
2672 KB |
Output is correct |
10 |
Correct |
57 ms |
1876 KB |
Output is correct |
11 |
Correct |
42 ms |
1492 KB |
Output is correct |
12 |
Correct |
35 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Incorrect |
6 ms |
340 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
200 ms |
5008 KB |
Output is correct |
12 |
Correct |
201 ms |
4940 KB |
Output is correct |
13 |
Correct |
157 ms |
5016 KB |
Output is correct |
14 |
Incorrect |
496 ms |
5012 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
84 ms |
2672 KB |
Output is correct |
10 |
Correct |
57 ms |
1876 KB |
Output is correct |
11 |
Correct |
42 ms |
1492 KB |
Output is correct |
12 |
Correct |
35 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Incorrect |
6 ms |
340 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
200 ms |
5008 KB |
Output is correct |
12 |
Correct |
201 ms |
4940 KB |
Output is correct |
13 |
Correct |
157 ms |
5016 KB |
Output is correct |
14 |
Incorrect |
496 ms |
5012 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |