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 iter(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
ll iceil(ll a, ll b){
return (a + b - 1) / b;
}
int n;
ll m;
vector<ll> a, b;
bool check(ll mn){
ll cnt = 0;
for(int i = 1; i <= n; i++){
ll need = iceil(mn, a[i]);
if(need <= m){
cnt += m - need;
continue;
}
ll tmp = mn - m * a[i];
assert(tmp > 0);
cnt -= iceil(tmp, b[i]);
}
return cnt >= 0;
}
mt19937 rnd(123123);
uniform_int_distribution<int> ud(48763, 123456);
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
a.resize(n + 1);
b.resize(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> b[i];
//for(int i = 1; i <= n; i++) a[i] = ud(rnd);
//for(int i = 1; i <= n; i++) b[i] = ud(rnd);
for(int i = 1; i <= n; i++) a[i] = max(a[i], b[i]);
//for(int i = 1; i <= 10; i++) cerr << check(i) << " ";
//cerr << "\n";
ll tans = *min_element(a.begin() + 1, a.end());
//cout << *min_element(a.begin() + 1, a.end()) << "\n";
//return 0;
ll l = 0, r = 1e15;
while(l < r){
ll mid = (l + r + 1) / 2;
if(check(mid)) l = mid;
else r = mid - 1;
}
cout << l << "\n";
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:54:8: warning: unused variable 'tans' [-Wunused-variable]
54 | ll tans = *min_element(a.begin() + 1, a.end());
| ^~~~
# | 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... |