Submission #1018837

#TimeUsernameProblemLanguageResultExecution timeMemory
1018837vjudge1Self Study (JOI22_ho_t2)C++14
100 / 100
123 ms5208 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define boost ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const int N = 1e6 + 12, INF = 1e9 + 7;
signed main () {
	boost
	int n, m;
	cin >> n >> m;
	vector<int>a(n), b(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	for(int i = 0; i < n; ++i){
		cin >> b[i];
	}
	
	auto just = [&](int p){
		int t = 0;
		for(int i = 0; i < n; ++i){
			if(b[i] > a[i]){
				int just1 = (p + b[i] - 1) / b[i];
				t += just1;
			} else {
				if(a[i] * m >= p){
					int just2 = (p + a[i] - 1) / a[i];
					t += just2;
				} else {
					int just2 = m;
					int just1= (p - a[i] * m + b[i] - 1) / b[i];
					t += just2 + just1;
				}
			}
			if(t > n * m) return false;
		}
		if(t <= n * m){
			return true;
		} else {
			return false;
		}
	};
	int l = 0, r = 1e18;
	while(r - l > 1){
		int m = (l + r) / 2;
		if(just(m)){
			l = m;
		} else {
			r = m;
		}
	}
	if(just(r)){
		cout << r;
	} else {
		cout << l;
	}
}
#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...