Submission #1115902

#TimeUsernameProblemLanguageResultExecution timeMemory
1115902TrieTrSelf Study (JOI22_ho_t2)C++14
100 / 100
133 ms15176 KiB
#include<bits/stdc++.h>
using namespace std;

void local() {
    #define taskname ""
    if (fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
}

#define ll long long
#define int long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<class X, class Y> bool mini(X &a, const Y &b) {return (a > b) ? a = b, true : false;}
template<class X, class Y> bool maxi(X &a, const Y &b) {return (a < b) ? a = b, true : false;}

const int N = 1e6 + 5;

int n, m;
int a[N], b[N];

bool check(ll x) {
	ll cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] > b[i]) {
			ll useA = min(m * 1ll, (x + a[i] - 1 ) / a[i]);
			ll useB = max(0ll, (x - useA * a[i] + b[i] - 1) / b[i]);
			cnt += useA + useB;		
		}
		else cnt += (x + b[i] - 1) / b[i];
		if(cnt > 1ll * n * m) return false;
	}
	return cnt <= 1ll * n * m;
}

signed main() {
    fastio; local();
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) cin >> b[i];
    ll lo = 1, hi = 1e18, res = 0;
	while(lo <= hi) {
		ll mid = (lo + hi) >> 1;
		if(check(mid)) lo = (res = mid) + 1;
		else hi = mid - 1;
	}
	cout << res;
}

Compilation message (stderr)

Main.cpp: In function 'void local()':
Main.cpp:7:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...