Submission #83462

# Submission time Handle Problem Language Result Execution time Memory
83462 2018-11-08T03:40:30 Z charlies_moo Cipele (COCI18_cipele) C++17
27 / 90
1000 ms 1356 KB
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
using namespace std;
int l[100010],r[100010];
int main(){
	int n,m,i,j,k;
	cin >> n >> m;
	for(i=1;i<=n;i++)
		cin >> l[i];
	for(i=1;i<=m;i++)
		cin >> r[i];
	sort(l+1,l+n+1);
	sort(r+1,r+m+1);
	if(n==m) {
        k=0;
		for(i=1;i<=n;i++) {
			if(abs(l[i]-r[i])>k)
				k=abs(l[i]-r[i]);
		}
	}
	else if(n>m) {
        i=1;
		int x=i+m;
		if(i+m>n)
			x=n;
		while(x<n && l[x]<r[0])
			x++;
		i=x-m;
		k=-1;
		for(;i<=n-m+1;i++)
		{
			int y = 0;
			for(j=1;j<=m;j++){
				if(abs(l[j+i-1]-r[j])>y)
					y=abs(l[j+i-1]-r[j]);
			}
			if(y<k || k==-1)
				k=y;
			if(l[i]>r[m])
				break;
		}
	}
	else
	{
	    i=1;
		int x=i+n;
		if(i+n>m)
			x=m;
		while(x<m && l[x]<r[0])
			x++;
		i=x-n;
		k=-1;
		for(;i<=m-n+1;i++)
		{
			int y = 0;
			for(j=1;j<=n;j++){
				if(abs(l[j]-r[j+i-1])>y)
					y=abs(l[j]-r[i+j-1]);
			}
			if(y<k || k==-1)
				k=y;
			if(r[i]>l[n])
				break;
		}
	}
	cout << k << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 99 ms 1148 KB Output is correct
2 Correct 126 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 1228 KB Output is correct
2 Correct 117 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1356 KB Output is correct
2 Correct 8 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 1356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 1356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 1356 KB Time limit exceeded
2 Halted 0 ms 0 KB -