이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define ep emplace
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
const ll INF=1e18;
const ll mod=1e9+7;
const int mxn=3e5+5;
ll a[mxn], b[mxn];
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
ll n, m; cin >> n >> m;
for(int i=0;i<n;i++) cin >> a[i];
for(int i=0;i<n;i++) cin >> b[i];
auto chk=[&](ll x)
{
ll ret=0;
for(int i=0;i<n;i++)
{
if(a[i]<=b[i]) ret+=(x+b[i]-1)/b[i];
else
{
ll cur=min(m, (x+a[i]-1)/a[i]);
ll nw=INF;
for(int j=max(cur-2, 0ll);j<=cur;j++)
{
ll rem=max(x-a[i]*j, 0ll);
nw=min(nw, j+(rem+b[i]-1)/b[i]);
}
ret+=nw;
}
if(ret>m*n) return false;
}
return true;
};
ll lo=0, hi=INF;
while(lo<hi)
{
ll m=(lo+hi+1)/2;
if(chk(m)) lo=m;
else hi=m-1;
}
cout << lo;
}
# | 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... |