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>
#include<fstream>
using namespace std;
ifstream fin("WINTER.inp");
ofstream fout("WINTER.out");
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const ll mod = 1e9 + 7;
const int mxn = 3e5 + 5, mxv = 1e6;
ll n, m;
ll a[mxn + 1], b[mxn + 1];
bool ck(ll mid){
ll need = 0;
forr(i, 0, n){
ll have = max(a[i], b[i]) * m;
need += min(m, (ll)ceil((ld)(mid) / (ld)(max(a[i], b[i]))));
if(mid > have){
need += ceil((ld)(mid - have) / (ld)(b[i]));
}
}
return(need <= n * m);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
forr(i, 0, n){
cin >> a[i];
}
forr(i, 0, n)cin >> b[i];
ll l = 1, r= 1e18, ans = 0;
while(l <= r){
ll mid = (l + r) >> 1;
if(ck(mid)){
ans = mid; l = mid + 1;
}else{
r = mid - 1;
}
}
cout << ans;
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... |