# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
914973 | 2024-01-23T03:49:42 Z | ReLice | Self Study (JOI22_ho_t2) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #define ll long long #define str string #define ins insert #define ld long double #define pb push_back #define pf push_front #define pof pop_front() #define pob pop_back() #define lb lower_bound #define ub upper_bound #define endl "\n" #define fr first #define sc second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define sz size() #define vll vector<ll> #define bc back() #define arr array #define pll vector<pair<ll,ll>> using namespace std; template <class _T> bool chmin(_T &x, const _T &y){ bool f=0; if (x>y){x=y;f=1;} return f; } template <class _T> bool chmax(_T &x, const _T &y){ bool f=0; if (x<y){x=y;f=1;} return f; } //void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} void start(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll inf=2e18+7; const ll mod=1e9+7; const ll N=1e5+7; const ld eps=1e-9; istream& operator>>( istream& src, __int128_t& value) { long long v;src>>v; value = (ll)v; return src; } void solve(){ ll i,j; ll n,m;cin>>n>>m; vi a(n);rep(i,0,n)cin>>a[i]; vi b(n);rep(i,0,n)cin>>b[i]; rep(i,0,n)a[i]=max(a[i],b[i]); if(m==1){ ll ans=inf; for(i=0;i<n;i++) ans=min(ans,a[i]); cout<<ans<<endl; return; } ll lo = 0; ll hi = 2e18; while(lo+1<hi){ ll mid = lo+(hi-lo)/2; ll cost = 0; for(i=0;i<n;i++) { ll inclass = (mid+a[i]-1)/a[i]; if(inclass>m){ inclass=m; ll outclass = (mid-inclass*a[i]+b[i]-1)/b[i]; cost+=outclass; } cost+=inclass; } if(cost<=n*m) lo=mid; else hi=mid; } cout<<lo<<endl; } signed main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); ll t=1; //cin>>t; while(t--) solve(); return 0; } /* */