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 endl '\n'
using namespace std;
const long long MAXN = 3e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long n, m;
long long a[MAXN], b[MAXN];
void read()
{
cin >> n >> m;
for (long long i = 1; i <= n; ++ i)
cin >> a[i];
for (long long i = 1; i <= n; ++ i)
cin >> b[i];
}
long long useda[MAXN], needb[MAXN];
bool check(long long x)
{
memset(useda, 0, sizeof(useda));
memset(needb, 0, sizeof(needb));
long long suma = 0, sumb = 0;
for (long long i = 1; i <= n; ++ i)
{
if(a[i] > b[i])
{
long long times = x / a[i];
if(x % a[i] != 0)times ++;
times = min(m, times);
useda[i] = times;
long long ost = max(1LL * 0, x - times * a[i]);
needb[i] = ost / b[i];
if(ost % b[i] != 0)needb[i] ++;
}
else
{
needb[i] = x / b[i];
if(x % b[i] != 0)needb[i] ++;
}
suma += useda[i];
sumb += needb[i];
if(suma + sumb > n * m)return false;
}
return (sumb <= n * m - suma);
}
void solve()
{
long long l = 0, r = 1e17, mid, ans = 0;
while(l <= r)
{
mid = (l + r)/2;
if(check(mid))
{
ans = mid;
l = mid + 1LL * 1;
}
else r = mid - 1LL * 1;
}
cout << ans << endl;
}
int main()
{
speed();
read();
solve();
return 0;
}
# | 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... |