Submission #936651

#TimeUsernameProblemLanguageResultExecution timeMemory
936651william950615Self Study (JOI22_ho_t2)C++14
100 / 100
276 ms10884 KiB
#include<bits/stdc++.h> using namespace std; #define F first #define S second #define mkp make_pair #define PH push #define PB push_back #define REP(i,N) for( int i = 0; i < (N); ++i ) #define FOR(i,a,b) for( int i = (a); i <= (b); ++i ) #define ALL(x) begin(x), end(x) #define MEM(x) memset(x, 0, sizeof(x)) typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; template<typename T> using V=vector<T>; void solve() { int N, M; cin >> N >> M; V<pll> vc(N); for( auto &i : vc ) cin >> i.F; for( auto &i : vc ) cin >> i.S; ll total = 1LL*N*M; auto check = [&]( ll val ) { __int128 sum = 0; for( auto &i : vc ){ if( i.F > i.S ) { ll cnt = (val+i.F-1)/i.F; cnt = min( cnt, (ll)M ); sum += cnt; if( cnt*i.F < val ) { sum += (val-cnt*i.F+i.S-1)/i.S; } } else { sum += (val+i.S-1)/i.S; } } return sum; }; ll l = 0, r = 1e18+3000; while( r-l > 1 ) { ll m = (l+r)>>1; if( check(m)<=total ) l=m; else r=m; } cout << l << '\n'; } int main() { int T = 1; #ifdef LOCAL freopen( "input.txt", "r", stdin); freopen( "output.txt", "w", stdout ); cin >> T; #else ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif while(T--) solve(); }
#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...