# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1184458 | nguyn | Self Study (JOI22_ho_t2) | C++20 | 156 ms | 7484 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
const int N = 3e5 + 5;
int n, m;
int a[N], b[N];
int c[N];
bool check(int mid) {
int cur = 0;
for (int i = 1; i <= n; i++) {
int t = (mid + a[i] - 1) / a[i];
if (t <= m) {
c[i] = 0;
cur += m - t;
}
else {
c[i] = mid - a[i] * m;
}
}
// for (int i = 1; i <= n; i++) {
// cout << c[i] << ' ';
// } cout << endl;
for (int i = 1; i <= n; i++) {
int t = (c[i] + b[i] - 1) / b[i];
if (cur < t) {
return 0;
}
else {
cur -= t;
}
}
return 1;
}
signed main(){
ios_base::sync_with_stdio(false) ;
cin.tie(0) ; cout.tie(0) ;
if (fopen("INP.INP" ,"r")) {
freopen("INP.INP" ,"r" , stdin) ;
freopen("OUT.OUT" , "w" , stdout) ;
}
cin >> n >> m;
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] = max(a[i], b[i]);
}
int l = 1;
int r = 1e18;
int res = 0;
while(l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
l = mid + 1;
res = mid;
}
else {
r = mid - 1;
}
}
cout << res;
}
Compilation message (stderr)
# | 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... |