Submission #531714

#TimeUsernameProblemLanguageResultExecution timeMemory
531714errorgornSelf Study (JOI22_ho_t2)C++17
100 / 100
376 ms11412 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

ll n,m;
ll arr[300005];
ll brr[300005];

bool can(ll val){
	__int128 extra=0;
	
	rep(x,0,n){
		ll temp=(val+arr[x]-1)/arr[x];
		
		if (temp<=m) extra+=m-temp;
		else{
			ll nv=val-m*arr[x];
			extra-=(nv+brr[x]-1)/brr[x];
		}
	}
	
	return extra>=0;
}

signed main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n>>m;
	rep(x,0,n) cin>>arr[x];
	rep(x,0,n) cin>>brr[x];
	
	rep(x,0,n) assert(brr[x]>0);
	
	rep(x,0,n) arr[x]=max(arr[x],brr[x]);
	
	ll lo=0,hi=1e18+100,mi;
	while (hi-lo>1){
		mi=hi+lo>>1;
		
		if (can(mi)) lo=mi;
		else hi=mi;
	}
	
	cout<<lo<<endl;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:58:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |   mi=hi+lo>>1;
      |      ~~^~~
#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...