Submission #955037

# Submission time Handle Problem Language Result Execution time Memory
955037 2024-03-29T08:26:08 Z sleepntsheep Self Study (JOI22_ho_t2) C
100 / 100
395 ms 13396 KB
#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;
        if((k+a[i]-1)/a[i]<=m) lf=0;
        else lf=k-m*1ll*a[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];

    for(int i=1;i<=n;++i)
    {
        take+=bb[i];
        if(take>free)return 0;
    }

    return 1;
}

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=3e18+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:34:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d%d",&n,&m);
      |     ^~~~~~~~~~~~~~~~~~~
Main.c:35:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     for(int i=1;i<=n;++i)scanf("%d",a+i);
      |                          ^~~~~~~~~~~~~~~
Main.c:36:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     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 1 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 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 1 ms 4444 KB Output is correct
10 Correct 5 ms 4444 KB Output is correct
11 Correct 274 ms 7436 KB Output is correct
12 Correct 273 ms 7248 KB Output is correct
13 Correct 266 ms 7248 KB Output is correct
14 Correct 310 ms 7664 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 375 ms 7248 KB Output is correct
17 Correct 268 ms 7652 KB Output is correct
18 Correct 274 ms 7432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 375 ms 7248 KB Output is correct
3 Correct 268 ms 7652 KB Output is correct
4 Correct 274 ms 7432 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 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 140 ms 5708 KB Output is correct
14 Correct 94 ms 4952 KB Output is correct
15 Correct 69 ms 4700 KB Output is correct
16 Correct 57 ms 4696 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4516 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 7 ms 4444 KB Output is correct
23 Correct 5 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 4444 KB Output is correct
10 Correct 5 ms 4444 KB Output is correct
11 Correct 274 ms 7436 KB Output is correct
12 Correct 273 ms 7248 KB Output is correct
13 Correct 266 ms 7248 KB Output is correct
14 Correct 310 ms 7664 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 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 140 ms 5708 KB Output is correct
24 Correct 94 ms 4952 KB Output is correct
25 Correct 69 ms 4700 KB Output is correct
26 Correct 57 ms 4696 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 4516 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 7 ms 4444 KB Output is correct
33 Correct 5 ms 4440 KB Output is correct
34 Correct 1 ms 4440 KB Output is correct
35 Correct 375 ms 7248 KB Output is correct
36 Correct 268 ms 7652 KB Output is correct
37 Correct 274 ms 7432 KB Output is correct
38 Correct 1 ms 4528 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4440 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 6 ms 4444 KB Output is correct
46 Correct 9 ms 4444 KB Output is correct
47 Correct 1 ms 4440 KB Output is correct
48 Correct 48 ms 4700 KB Output is correct
49 Correct 1 ms 4440 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 5 ms 4444 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 139 ms 5696 KB Output is correct
56 Correct 91 ms 5460 KB Output is correct
57 Correct 104 ms 5128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 4444 KB Output is correct
9 Correct 140 ms 5708 KB Output is correct
10 Correct 94 ms 4952 KB Output is correct
11 Correct 69 ms 4700 KB Output is correct
12 Correct 57 ms 4696 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4516 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 7 ms 4444 KB Output is correct
19 Correct 5 ms 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 375 ms 7248 KB Output is correct
22 Correct 268 ms 7652 KB Output is correct
23 Correct 274 ms 7432 KB Output is correct
24 Correct 49 ms 4700 KB Output is correct
25 Correct 138 ms 5524 KB Output is correct
26 Correct 31 ms 4696 KB Output is correct
27 Correct 276 ms 7252 KB Output is correct
28 Correct 282 ms 7252 KB Output is correct
29 Correct 280 ms 7432 KB Output is correct
30 Correct 291 ms 7436 KB Output is correct
31 Correct 318 ms 7504 KB Output is correct
32 Correct 382 ms 7256 KB Output is correct
33 Correct 321 ms 7432 KB Output is correct
34 Correct 395 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 4444 KB Output is correct
10 Correct 5 ms 4444 KB Output is correct
11 Correct 274 ms 7436 KB Output is correct
12 Correct 273 ms 7248 KB Output is correct
13 Correct 266 ms 7248 KB Output is correct
14 Correct 310 ms 7664 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 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 140 ms 5708 KB Output is correct
24 Correct 94 ms 4952 KB Output is correct
25 Correct 69 ms 4700 KB Output is correct
26 Correct 57 ms 4696 KB Output is correct
27 Correct 1 ms 4440 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 1 ms 4516 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 7 ms 4444 KB Output is correct
33 Correct 5 ms 4440 KB Output is correct
34 Correct 1 ms 4528 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4440 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 6 ms 4444 KB Output is correct
42 Correct 9 ms 4444 KB Output is correct
43 Correct 1 ms 4440 KB Output is correct
44 Correct 48 ms 4700 KB Output is correct
45 Correct 1 ms 4440 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 5 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 139 ms 5696 KB Output is correct
52 Correct 91 ms 5460 KB Output is correct
53 Correct 104 ms 5128 KB Output is correct
54 Correct 49 ms 4700 KB Output is correct
55 Correct 138 ms 5524 KB Output is correct
56 Correct 31 ms 4696 KB Output is correct
57 Correct 276 ms 7252 KB Output is correct
58 Correct 282 ms 7252 KB Output is correct
59 Correct 280 ms 7432 KB Output is correct
60 Correct 291 ms 7436 KB Output is correct
61 Correct 318 ms 7504 KB Output is correct
62 Correct 382 ms 7256 KB Output is correct
63 Correct 321 ms 7432 KB Output is correct
64 Correct 395 ms 8528 KB Output is correct
65 Correct 1 ms 4440 KB Output is correct
66 Correct 375 ms 7248 KB Output is correct
67 Correct 268 ms 7652 KB Output is correct
68 Correct 274 ms 7432 KB Output is correct
69 Correct 35 ms 5208 KB Output is correct
70 Correct 10 ms 4696 KB Output is correct
71 Correct 1 ms 4444 KB Output is correct
72 Correct 48 ms 5468 KB Output is correct
73 Correct 11 ms 4752 KB Output is correct
74 Correct 2 ms 4540 KB Output is correct
75 Correct 284 ms 13140 KB Output is correct
76 Correct 289 ms 13396 KB Output is correct
77 Correct 292 ms 13228 KB Output is correct
78 Correct 313 ms 13136 KB Output is correct
79 Correct 332 ms 13392 KB Output is correct
80 Correct 329 ms 13228 KB Output is correct
81 Correct 315 ms 11252 KB Output is correct
82 Correct 341 ms 11248 KB Output is correct