Submission #534223

#TimeUsernameProblemLanguageResultExecution timeMemory
534223LittleOrangeSelf Study (JOI22_ho_t2)C++17
100 / 100
250 ms6876 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,m; vector<ll> a,b; bool isok(ll target){ // ans>=target; ll time = 0; for (ll i = 0;i<n;i++){ ll x = m; ll t = target - x*a[i]; if (t<=-a[i]){ x -= (-t)/a[i]; t = target - x*a[i]; }else if (t>0){ x += t/b[i]; t -= (t/b[i])*b[i]; while (t>0){ x++; t-=b[i]; } } time += x; if (time>n*m) return false; } return true; } ll check(ll l, ll r){ if (l >= r) return l; ll mid = (l+r)/2; if (isok(mid+1)){ return check(mid+1,r); }else{ return check(l,mid); } } int main(){ ios::sync_with_stdio(0);cin.tie(0); cin >> n >> m; a.resize(n,0); b.resize(n,0); for (ll i = 0;i<n;i++){ cin >> a[i]; } for (ll i = 0;i<n;i++){ cin >> b[i]; a[i] = max(a[i], b[i]); } cout << check(0,5e18) << "\n"; }
#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...