제출 #648145

#제출 시각아이디문제언어결과실행 시간메모리
648145alanlSelf Study (JOI22_ho_t2)C++14
100 / 100
241 ms11448 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define rep(X, a,b) for(int X=a;X<b;++X)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (int)(a).size()
#define NL "\n"
using namespace std;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef long long ll;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, const vector<A> &p){
	for(const auto &a:p)
		os << a << " ";
	os << "\n";
	return os;
}

ll n, m;
ll a[300010], b[300010];

int check(ll x){
	ll day=0;
	rep(i,0,n){
		if(max(a[i], b[i])*m>=x) day+=(x+max(a[i], b[i])-1)/max(a[i], b[i]);
		else day+=m+(x-max(a[i], b[i])*m+b[i]-1)/b[i];
		if(day>n*m) return 0;
	}
	return 1;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	rep(i,0,n) cin>>a[i];
	rep(i,0,n) cin>>b[i];
	ll l=0, r=1ll<<60;
	while(l<r-1){
		ll mid=(l+r)>>1;
		if(check(mid)) l=mid;
		else r=mid;
	}
	cout<<l<<NL;
}
#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...