Submission #779146

# Submission time Handle Problem Language Result Execution time Memory
779146 2023-07-11T08:27:40 Z vjudge1 Cipele (COCI18_cipele) C++17
18 / 90
41 ms 1744 KB
//#include<bits/stdc++.h>
#include<iostream>
#include<bitset>
#include<algorithm>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define pb push_back
#define N 100005
bitset<N>  var;
int 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 mx=0;
		for(int i=0;i<n;i++){
			int l=0,r=m-1;
			while(l<r){
				int mid=(l+r)/2;
				if(sol[mid]>sa[i]){
					r=mid;
				}
				else l=mid+1;
			}
			int a=l,b=l;
			if(l!=0)a--;
			if(var[a]&&a){
				a--;
			}
			while(var[b]&&b!=m-1){
				b++;
			}
			if(var[a]||abs(sol[b]-sa[i])<=abs(sol[a]-sa[i])){
				mx=max(mx,abs(sol[b]-sa[i]));
			}
			else{
				mx=max(mx,abs(sol[a]-sa[i]));
			}
			var[a]=1;
			var[b]=1;
		}
		cout<<mx<<endl;
	}
	else{
		int mx=0;
		for(int i=0;i<m;i++){
			int l=0,r=n-1;
			while(l<r){
				int mid=(l+r)/2;
				if(sa[mid]>sol[i]){
					r=mid;
				}
				else l=mid+1;
			}
			int a=l,b=l;
			if(l!=0)a--;
			if(var[a]&&a){
				a--;
			}
			while(var[b]&&b!=n-1){
				b++;
			}

			//cout<<i<<" "<<a<<" "<<b<<endl;
			if(var[a]||abs(sa[b]-sol[i])<=abs(sa[a]-sol[i])){
				mx=max(mx,abs(sa[b]-sol[i]));
			}
			else{
				mx=max(mx,abs(sa[a]-sol[i]));
			}
			var[a]=1;
			var[b]=1;
		}
		cout<<mx<<endl;
	}

}


# Verdict Execution time Memory Grader output
1 Correct 16 ms 1620 KB Output is correct
2 Correct 28 ms 1728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1744 KB Output is correct
2 Correct 27 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 1596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 1648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 1564 KB Output isn't correct
2 Halted 0 ms 0 KB -