Submission #1223222

#TimeUsernameProblemLanguageResultExecution timeMemory
1223222TadijaSebezSelf Study (JOI22_ho_t2)C++20
62 / 100
91 ms2632 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

const int N=300050;
int a[N],b[N];

int main(){
    int n,m;
    scanf("%i %i",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%i",&a[i]);
    }
    for(int i=1;i<=n;i++){
        scanf("%i",&b[i]);
    }
    ll top=3e15,bot=0,ans=0;
    while(top>=bot){
        ll mid=top+bot>>1;
        ll need=0;
        ll have=0;
        for(int i=1;i<=n;i++){
            if(b[i]>=a[i]){
                need+=(mid+b[i]-1)/b[i];
                have+=m;
            }else{
                ll tmp=(mid+a[i]-1)/a[i];
                if(tmp<=m){
                    have+=m-tmp;
                }else{
                    need+=(mid-(ll)a[i]*m+b[i]-1)/b[i];
                }
            }
            if(need>(ll)n*m)break;
        }
        if(need>have){
            top=mid-1;
        }else{
            ans=mid;
            bot=mid+1;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%i %i",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
Main.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%i",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%i",&b[i]);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...