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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nemeshay ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define allr(pon) pon.rbegin(), pon.rend()
#define all(pon) pon.begin(), pon.end()
#define nosolve cout << "-1\n"
#define YES cout << "YES\n"
#define Yes cout << "Yes\n"
#define pii pair <int, int>
#define OK cout << "OK\n"
#define Ok cout << "Ok\n"
#define NO cout << "NO\n"
#define No cout << "No\n"
#define pf push_front
#define int long long
#define pb push_back
#define sigma signed
#define sc second
#define fr first
using namespace __gnu_pbds;
using namespace std;
const int N = 1e6 + 20, INF = 1e9 + 17;
int a[N], b[N];
sigma main(){
nemeshay
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
auto check = [&](int med) {
int t = 0;
for (int i = 0; i < n; i++) {
if (b[i] > a[i]) t += (med + b[i] - 1) / b[i];
else {
if (a[i] * m >= med) t += (med + a[i] - 1) / a[i];
else t += (med - a[i] * m + b[i] - 1) / b[i] + m;
}
if (t > n * m) return 0;
}
if (t <= n * m) return 1;
return 0;
};
int l = 0, r = 1e18;
while (r - l > 1) {
int med = l + r >> 1;
if (check(med)) l = med;
else r = med;
}
if (check(r)) cout << r;
else cout << l;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:47:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
47 | int med = l + r >> 1;
| ~~^~~| # | 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... |