Submission #779095

# Submission time Handle Problem Language Result Execution time Memory
779095 2023-07-11T07:46:43 Z vjudge1 Cipele (COCI18_cipele) C++17
18 / 90
1000 ms 1884 KB
#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define endl "\n"
#define int long long int
#define pb push_back

signed main(){
	lalala;
	int n,m;cin>>n>>m;

	int sa[n],sol[m];
	for(int i=0;i<n;i++)cin>>sa[i];
	for(int i=0;i<m;i++)cin>>sol[i];
	sort(sa,sa+n);
	sort(sol,sol+m);
	if(n==m){
		int mx=0;
		for(int i=0;i<n;i++)mx=max(mx,abs(sa[i]-sol[i]));
		cout<<mx<<endl;
		return 0;
	}
	if(n<m){
		int mn=0;
		int l=0,r=m-n;
		while(l<r){
			int mid=(l+r)/2;
			int mx=0,mx2=-1,mx1=-1;
			for(int i=mid;i<n+mid;i++){
				mx=max(mx,abs(sa[i-mid]-sol[i]));
			}
			if(mid!=0){
				for(int i=mid-1;i<n+mid-1;i++){
					mx1=max(mx1,abs(sa[i-mid+1]-sol[i]));
				}
			}
			if(mid!=m-n){
				for(int i=mid+1;i<n+mid+1;i++){
					mx2=max(mx2,abs(sa[i-mid-1]-sol[i]));
				}
			}
			if(mx1==-1){
				if(mx<=mx2){
					l=mid;break;
				}
				else{
					l=mid+1;
				}
				continue;
			}
			if(mx2==-1){
				if(mx<=mx1){
					l=mid;break;
				}
				else r=mid-1;
				continue;
			}
			l=mid-1;r=mid+1;
			if(mx1<mx)r=mid-1;
			if(mx>mx2)l=mid+1;
		}
		for(int i=l;i<n+l;i++){
				mn=max(mn,abs(sa[i-l]-sol[i]));
		}
		cout<<mn<<endl;
		return 0;
	}
	int mn=0;
	int l=0,r=n-m;
		while(l<r){
		int mid=(l+r)/2;
		int mx=0,mx2=-1,mx1=-1;
		for(int i=mid;i<m+mid;i++){
			mx=max(mx,abs(sa[i]-sol[i-mid]));
		}
		if(mid!=0){
			for(int i=mid-1;i<m+mid-1;i++){
				mx1=max(mx1,abs(sa[i]-sol[i-mid+1]));
			}
		}
		if(mid!=n-m){
			for(int i=mid+1;i<m+mid+1;i++){
				mx2=max(mx2,abs(sa[i]-sol[i-mid-1]));
			}
		}
		if(mx1==-1){
			if(mx<=mx2){
				l=mid;break;
			}
			else{
				l=mid+1;
			}
			continue;
		}
		if(mx2==-1){
			if(mx<=mx1){
				l=mid;break;
			}
			else r=mid-1;
			continue;
		}
		l=mid-1;r=mid+1;
		if(mx1<mx)r=mid-1;
		if(mx>mx2)l=mid+1;
	}
	for(int i=l;i<m+l;i++){
		mn=max(mn,abs(sa[i]-sol[i-l]));
	}
	cout<<mn<<endl;
	return 0;




}


# Verdict Execution time Memory Grader output
1 Correct 16 ms 1876 KB Output is correct
2 Correct 28 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1876 KB Output is correct
2 Correct 27 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 1684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 1620 KB Output isn't correct
2 Halted 0 ms 0 KB -