Submission #551453

#TimeUsernameProblemLanguageResultExecution timeMemory
551453toloraiaSelf Study (JOI22_ho_t2)C++14
100 / 100
277 ms5112 KiB
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back #define ull unsigned ll using namespace std; const ll linf = 3e18 + 1; bool check(ll a[], ll b[], ll x, ll n, ll m){ ll cnt = 0; for(int i = 1; i <= n; i++){ ll cnta; if(b[i] >= a[i])cnta = 0; else{ cnta = x / a[i]; if(x % a[i]) cnta++; cnta = min(cnta, m); } ll cur = x - a[i] * cnta; cnt += cnta; if(cnt > n * m) return false; if(cur < 0) continue; else{ cnt += cur / b[i]; if(cur % b[i])cnt++; if(cnt > n * m) return false; } } return true; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; ll m; cin >> m; ll a[n + 1]; ll b[n + 1]; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i <= n; i++){ cin >> b[i]; assert (max (a[i],b[i]) <= 1e9); } ll l = 0, r = linf; while(l + 1 < r){ ll mid = (l + r) / 2; if(check(a, b, mid, n, m))l = mid; else r = mid; } cout << l; 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...