#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=1e15+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]);
| ^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
3 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 |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
4 ms |
4444 KB |
Output is correct |
11 |
Correct |
205 ms |
13208 KB |
Output is correct |
12 |
Correct |
213 ms |
13080 KB |
Output is correct |
13 |
Correct |
200 ms |
11024 KB |
Output is correct |
14 |
Incorrect |
319 ms |
11248 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4524 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 |
4524 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
106 ms |
8612 KB |
Output is correct |
10 |
Correct |
70 ms |
7004 KB |
Output is correct |
11 |
Correct |
52 ms |
6284 KB |
Output is correct |
12 |
Correct |
42 ms |
5892 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 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 |
4440 KB |
Output is correct |
18 |
Correct |
5 ms |
4564 KB |
Output is correct |
19 |
Correct |
4 ms |
4536 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Incorrect |
378 ms |
8788 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
3 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 |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
4 ms |
4444 KB |
Output is correct |
11 |
Correct |
205 ms |
13208 KB |
Output is correct |
12 |
Correct |
213 ms |
13080 KB |
Output is correct |
13 |
Correct |
200 ms |
11024 KB |
Output is correct |
14 |
Incorrect |
319 ms |
11248 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4524 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 |
4524 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
106 ms |
8612 KB |
Output is correct |
10 |
Correct |
70 ms |
7004 KB |
Output is correct |
11 |
Correct |
52 ms |
6284 KB |
Output is correct |
12 |
Correct |
42 ms |
5892 KB |
Output is correct |
13 |
Correct |
1 ms |
4440 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 |
4440 KB |
Output is correct |
18 |
Correct |
5 ms |
4564 KB |
Output is correct |
19 |
Correct |
4 ms |
4536 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Incorrect |
378 ms |
8788 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
3 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 |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4440 KB |
Output is correct |
10 |
Correct |
4 ms |
4444 KB |
Output is correct |
11 |
Correct |
205 ms |
13208 KB |
Output is correct |
12 |
Correct |
213 ms |
13080 KB |
Output is correct |
13 |
Correct |
200 ms |
11024 KB |
Output is correct |
14 |
Incorrect |
319 ms |
11248 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |