Submission #1174784

#TimeUsernameProblemLanguageResultExecution timeMemory
1174784TsaganaSelf Study (JOI22_ho_t2)C++20
0 / 100
0 ms324 KiB
#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second

using namespace std;

int n, k;
int a[300010];
int b[300010];

bool check(int m, int c = 0) {
	for (int i = 1; i <= n; i++) {
		if (b[i] >= a[i]) {
			int x = m / b[i];
			if (b[i] * x < m) x++;
			c += k - x;
		}
		else {
			int x = m / a[i];
			if (a[i] * x < m) x++;
			if (x <= k) c += k - x;
			else {
				int r = (m - (a[i] * k));
				int y = r / (a[i] - b[i]);
				if ((a[i] - b[i]) * y < r) y++;
				c -= y;
			}
		}
	}
	return c >= 0;
}

int search(int l, int r, int ans = 0) {
	while (l < r) {
		int m = (l + r) / 2;
		if (check(m)) {ans = m; l = m + 1;}
		else r = m - 1;
	}
	return ans;
}

void solve () {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	cout << search(0, 1e9) << '\n';
}
signed main() {IOS solve(); return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...