Submission #551445

# Submission time Handle Problem Language Result Execution time Memory
551445 2022-04-20T17:38:34 Z luka1234 Self Study (JOI22_ho_t2) C++14
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
ll n,m;
ll a[300001],b[300001];
bool check(ll f){
	ll raod=n*m;
	vector<ll> v;
	ll cnt=0;
	for(ll k=1;k<=n;k++){
		if(b[k]>=a[k]){
			cnt=f/b[k];
			if(f%b[k]!=0)
			   cnt++;
			if(cnt>raod)
			   return 0;
			raod-=cnt;
		}
		else{
			v.push_back(k);
		}
	}
	ll dar=0;
	for(ll ind:v){
		ll i=a[ind];
		ll j=b[ind];
		cnt=f/i;
		if(f%i!=0)
		   cnt++;
		if(cnt>m)
		   cnt=m;
		if(raod<cnt)
		   return 0;
		raod-=cnt;
		dar=f-cnt*i;
		if(dar<=0)
		   continue;
		cnt=dar/j;
		if(dar%j!=0)
		   cnt++;
		if(raod<cnt)
		   return 0;
		raod-=cnt;
	}
	if(raod<0)
	   return 0;
	else
	   return 1;
}
int main(){
	cin>>n>>m;
	for(ll k=1;k<=n;k++){
		cin>>a[k];
	}
	for(ll k=1;k<=m;k++){
		cin>>b[k];
	}
	ll l=0,r=3e14;
	ll md;
	bool bl;
	while(l<r){
		md=(l+r+1)/2;
		bl=check(md);
		if(bl==1){
			l=md;
		}
		else{
			r=md-1;
		}
	}
	cout<<l;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 8
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 8
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 8
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 8
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 8
3 Halted 0 ms 0 KB -