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>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = INT_MAX;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
const double eps = 1e-12;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
const int MAX = 300010;
int n, m;
int A[MAX], B[MAX];
bool check(int T){
int rem = n*m;
FOR(i, 1, n, 1){
int cost = 0;
int tmp = T;
if(A[i] > B[i]){ // use A first
if(tmp > A[i] * m){ // A -> B
rem -= m;
tmp -= A[i] * m;
cost = (tmp + B[i] - 1) / B[i];
rem -= cost;
}
else{ // A only
cost = (tmp + A[i] - 1) / A[i];
rem -= cost;
}
}
else{ // always use B
cost = (T + B[i] - 1) / B[i];
rem -= cost;
}
if(rem < 0) return 0;
}
return 1;
//cerr<<"check "<<T<<" : rem = "<<rem<<endl;
//return (rem >= 0);
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
FOR(i, 1, n, 1){
cin>>A[i];
}
FOR(i, 1, n, 1){
cin>>B[i];
}
int L = 0, R = LNF, mid;
while(L < R){
mid = (L + R + 1) / 2;
if(check(mid)) L = mid;
else R = mid - 1;
}
cout<<L<<'\n';
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... |