This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll a[maxN],b[maxN];
ll n,m;
bool check(ll mid)
{
ll sum=0;
for(int i=1;i<=n;i++)
{
ll cc=max(a[i],b[i]);
cc=(mid+cc-1)/cc;
if(cc<=m) sum+=m-cc;
else
{
cc=max(a[i],b[i]);
ll can=mid-cc*m;
can=(can+b[i]-1)/b[i];
sum-=can;
if(sum<-m*n) return false;
}
// cc*...>=mid
}
return sum>=0;
}
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
#define rand rd
void solve()
{
cin >> n >> m;
for(int i=1;i<=n;i++)
{
cin >> a[i];
}
for(int i=1;i<=n;i++)
{
cin >> b[i];
}
ll low=0,high=5e18;
ll ans=inf;
for(int i=1;i<=n;i++)
{
ans=min(ans,max(a[i],b[i]));
}
while(low<=high)
{
ll mid=low+high>>1;
if(check(mid)) low=mid+1;
else high=mid-1;
}
cout << high;
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:59:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
59 | ll mid=low+high>>1;
| ~~~^~~~~
# | 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... |