제출 #1328585

#제출 시각아이디문제언어결과실행 시간메모리
1328585tomthuy123Self Study (JOI22_ho_t2)C++20
0 / 100
61 ms15744 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9 + 7;

ll AllNegative=1;

ll SubtaskIV=1;
ll n,m;
ll check(ll x, vector<ll>& BLst, ll limit){
	ll total=0;
	for(ll i=0;i<n;i++){
		total+=(limit+BLst[i]-1)/BLst[i];
	}
	return total<=limit;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	
	
	cin >> n >> m;
	vector<ll> Alst(n);
	vector<ll> Blst(n);
	for(ll i=0;i<n;i++){
		cin >> Alst[i];
	}
	for(ll i=0;i<n;i++){
		cin >> Blst[i];
		if(Blst[i]!=Alst[i]){
			SubtaskIV=0;
		}
	}

	if(SubtaskIV==1){
		ll L=1;
		ll R=1e18;
		ll ans;
		while(L<=R){
			ll mid=L+(R-L)/2;
			if(check(mid, Blst, n*m)){
				ans=mid;
				L=mid+1;
			}
			else{
				R=mid-1;
			}
		}
		cout << ans;
		return 0;
	}

	vector<ll> Comprehension(n,0);
	for(ll i=0;i<n;i++){
		Comprehension[i]+=max(Alst[i],Blst[i]);
	}
	ll ans=LLONG_MAX;
	for(ll i:Comprehension){
		ans=min(ans,i);
	}
	priority_queue<pair<ll,ll>, vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
	for(ll i=0;i<n;i++){
		pq.push({Comprehension[i],i});
	}
	for(ll i=1;i<m;i++){
		for(ll j=0;j<n;j++){
			pair<ll,ll> Curr=pq.top();
			pq.pop();
			ll CurrAmount=Curr.first;
			ll CurrPos=Curr.second;
			if(j==CurrPos){
				CurrAmount+=max(Alst[CurrPos],Blst[CurrPos]);
			}
			else{
				CurrAmount+=Blst[CurrPos];
			}
			pq.push({CurrAmount,CurrPos});
		}
	}
	cout << (pq.top()).first;
	
}
#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...