제출 #1287450

#제출 시각아이디문제언어결과실행 시간메모리
1287450nasjesSelf Study (JOI22_ho_t2)C++20
54 / 100
162 ms5156 KiB
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll dim = 1e6+7;
const ll inf = 1e18 + 77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>

ll n, m;
ll a[dim], b[dim];
ll check(ll val){
    __int128 free=0;
    vector<pll> v;
    for(int i=1; i<=n; i++){
        ll f=m-(val+a[i]-1)/a[i];
        if(f>0)free+=f;
        else{
            free-=(val-a[i]*m-1+b[i])/b[i];
        }

    }
    if(free<0)return 0;
    return 1;


}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for(int i=1; i<=n; i++) {
        cin>>a[i];
    }
    for(int i=1; i<=n; i++) {
        cin>>b[i];
        a[i]=max(a[i], b[i]);
    }
    ll l=1;
    ll r=1e18;
    while(r-l>=1){
        ll mid=(l+r+1)/2;
        if(check(mid)){
            l=mid;
        }
        else{
            r=mid-1;
        }
    }
    cout<<l<<endl;
    return 0;
}
#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...