Submission #147041

# Submission time Handle Problem Language Result Execution time Memory
147041 2019-08-27T09:55:54 Z albino_ojuz Cipele (COCI18_cipele) C++14
18 / 90
163 ms 1160 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n,m;
int mini,maks;
int niz1[N],niz2[N];

bool f(int val, int plus) {//cout << "funkcija\n";
	for (int i = 0;i < n;i++) {
//		cout << i << " " << i + plus <<endl << endl;
		if (abs(niz1[i] - niz2[i + plus]) > val) {
			return false;
		}
	}
	return true;
}

int main () {
	
	cin >> n >> m;
	for (long long i = 0;i < n;i++) {
		cin >> niz1[i];
		if (niz1[i] > maks) {
			maks = niz1[i];
		}
		if (niz1[i] < mini) {
			mini = niz1[i];
		}
	}
	for (long long i = 0;i < m;i++) {
		cin >> niz2[i];
		if (niz2[i] > maks) {
			maks = niz2[i];
		}
		if (niz2[i] < mini) {
			mini = niz2[i];
		}
	}
	sort(niz1,niz1 + n);
	sort(niz2,niz2 + m);
	
	if (n > m) {
		for (long long i = 0;i < n;i++) {
			swap(niz1[i],niz2[i]);
		}
		swap(n,m);
	}
/*	
	for (int i = 0;i < n;i++) {
		cout << niz1[i] << " ";
	}cout << endl;
	for (int i = 0;i < niz2[i];i++) {
		cout << niz2[i] << " ";
	}cout << endl;
	
*/	
	int ind = 0;
	int lo = 0, hi = maks;
	while (lo != hi) {
		int mid = (lo + hi) / 2;
		int zas = 0;
		for (int i = 0;i <= m - n;i++) {
			if (abs(niz1[0] - niz2[i]) < mid) {
				bool b = f(mid,i);
				ind = i;
				if (b == 0) {
					zas = 1;
				}
				else {
				}
//				cout << mid << " " << i << " bool: " << b << endl;
				break;
			}
		}
		if (zas == 1) {
			lo = mid + 1;
		}
		else {
			hi = mid;
		}
	}
	while (f(lo-1,ind)) {
		lo--;
	} 
	for (int i = 0;i <= m - n;i++) {
		if (f(lo,i) == 1) {
			cout << lo << endl;
			return 0;
		}
	}
	
	cout << lo + 1 << endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 129 ms 1144 KB Output is correct
2 Correct 157 ms 1028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 1152 KB Output is correct
2 Correct 163 ms 1160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 10 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 128 ms 1008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 142 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 126 ms 872 KB Output isn't correct
2 Halted 0 ms 0 KB -