Submission #955032

# Submission time Handle Problem Language Result Execution time Memory
955032 2024-03-29T08:24:19 Z sleepntsheep Self Study (JOI22_ho_t2) C
0 / 100
1 ms 2396 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=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];

    for(int i=1;i<=n;++i)
    {
        take+=b[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=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 'ok':
Main.c:11:28: warning: variable 'bb' set but not used [-Wunused-but-set-variable]
   11 |     static long long aa[N],bb[N];
      |                            ^~
Main.c: In function 'main':
Main.c:32:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d%d",&n,&m);
      |     ^~~~~~~~~~~~~~~~~~~
Main.c:33:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     for(int i=1;i<=n;++i)scanf("%d",a+i);
      |                          ^~~~~~~~~~~~~~~
Main.c:34:26: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     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 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -