#include<stdio.h>
long long max_(long long a,long long b){return a>b?a:b;}
long long min_(long long a,long long b){return a<b?a:b;}
#define N 300005
int n,m,a[N],b[N];
int ok(long long k)
{
static long long aa[N],bb[N];
for(int i=1;i<=n;++i)
{
aa[i]=min_((k+a[i]-1)/a[i],m);
long long lf=max_(0,k-a[i]*aa[i]);
bb[i]=(lf+b[i]-1)/b[i];
}
long long free=0,take=0;
for(int i=1;i<=n;++i)free+=m-aa[i],take+=bb[i];
//printf(" : %lld = %lld %lld\n",k,free,take); for(int i=1;i<=n;++i) printf(" . %lld %lld\n",aa[i],bb[i]);
return take<=free;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)scanf("%d",a+i);
for(int i=1;i<=n;++i)scanf("%d",b+i),a[i]=max_(a[i],b[i]);
long long lower=-1,upper=1e18+5;
while(upper-lower>1)
{
long long mid=lower+(upper-lower)/2;
if(ok(mid))lower=mid;
else upper=mid;
}
printf("%lld",lower);
}
Compilation message
Main.c: In function 'main':
Main.c:26:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d%d",&n,&m);
| ^~~~~~~~~~~~~~~~~~~
Main.c:27:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | for(int i=1;i<=n;++i)scanf("%d",a+i);
| ^~~~~~~~~~~~~~~
Main.c:28:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | for(int i=1;i<=n;++i)scanf("%d",b+i),a[i]=max_(a[i],b[i]);
| ^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
5 ms |
4444 KB |
Output is correct |
11 |
Correct |
253 ms |
7328 KB |
Output is correct |
12 |
Correct |
251 ms |
7504 KB |
Output is correct |
13 |
Correct |
248 ms |
7436 KB |
Output is correct |
14 |
Incorrect |
437 ms |
7508 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
126 ms |
5712 KB |
Output is correct |
10 |
Correct |
86 ms |
5200 KB |
Output is correct |
11 |
Correct |
64 ms |
4832 KB |
Output is correct |
12 |
Correct |
52 ms |
4736 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4528 KB |
Output is correct |
18 |
Incorrect |
9 ms |
4444 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
5 ms |
4444 KB |
Output is correct |
11 |
Correct |
253 ms |
7328 KB |
Output is correct |
12 |
Correct |
251 ms |
7504 KB |
Output is correct |
13 |
Correct |
248 ms |
7436 KB |
Output is correct |
14 |
Incorrect |
437 ms |
7508 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
126 ms |
5712 KB |
Output is correct |
10 |
Correct |
86 ms |
5200 KB |
Output is correct |
11 |
Correct |
64 ms |
4832 KB |
Output is correct |
12 |
Correct |
52 ms |
4736 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4528 KB |
Output is correct |
18 |
Incorrect |
9 ms |
4444 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
5 ms |
4444 KB |
Output is correct |
11 |
Correct |
253 ms |
7328 KB |
Output is correct |
12 |
Correct |
251 ms |
7504 KB |
Output is correct |
13 |
Correct |
248 ms |
7436 KB |
Output is correct |
14 |
Incorrect |
437 ms |
7508 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |