# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1167203 | hainam2k9 | Self Study (JOI22_ho_t2) | C++20 | 199 ms | 6376 KiB |
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 3e5+5;
const string NAME = "";
int n,m,cnt[MAXN];
ll a[MAXN];
pair<int,int> p[MAXN];
bool check(ll x){
ll sum=0;
for(int i = 1; i<=n; ++i){
if(p[i].fi>p[i].se){
a[i]=min((x-1)/p[i].fi+1,1ll*m)*p[i].fi;
cnt[i]=m-min((x-1)/p[i].fi+1,1ll*m), sum+=cnt[i];
}else sum+=m, cnt[i]=0;
}
for(int i = 1; i<=n; ++i)
if(a[i]<x){
ll need=(x-a[i]-1)/p[i].se+1;
if(sum-cnt[i]<need) return 0;
sum-=need;
}
return 1;
}
ll bs(ll l, ll r){
ll rs=1;
while(l<=r){
ll mid=(l+r)>>1;
if(check(mid)) rs=mid, l=mid+1;
else r=mid-1;
}
return rs;
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n >> m;
for(int i = 1; i<=n; ++i)
cin >> p[i].fi;
for(int i = 1; i<=n; ++i)
cin >> p[i].se;
cout << bs(1,1e18);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |