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 ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define vl vector<ll>
#define sl set<ll>
#define pb push_back
#define all(v) v.begin(), v.end()
#define f first
#define s second
#define ld long double
using namespace std;
const int sz = 3e5+5;
ll n, m, i, j;
ll a[sz], b[sz];
bool check(ll mid)
{
ll need = 0;
for(i = 0; i < n; i++)
{
ll have = max(a[i], b[i]) * m, val = mid / max(a[i], b[i]);
if(mid % max(a[i], b[i])) val++;
need += min(val, m);
if(mid > have) need += ceil((ld)(mid-have) / (ld)(b[i]));
if(need > n * m) return false;
}
return (need <= n * m);
}
int main()
{
cin >> n >> m;
for(i = 0; i < n; i++) cin >> a[i];
for(i = 0; i < n; i++) cin >> b[i];
ll l = 1, r = 1e18, k = 0;
while(l <= r)
{
ll mid = (l + r) / 2;
if(check(mid))
{
k = mid;
l = mid + 1;
}
else r = mid - 1;
}
cout << k << "\n";
}
# | 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... |