Submission #147044

# Submission time Handle Problem Language Result Execution time Memory
147044 2019-08-27T10:08:18 Z albino_ojuz Cipele (COCI18_cipele) C++14
27 / 90
1000 ms 1156 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e5+5;
 
int n,m;
int mini,maks;
int niz1[N],niz2[N];
int minimum = 1e9+7;
 
bool f(int val, int plusic) {//cout << "funkcija\n";
	for (int i = 0;i < n;i++) {
//		cout << i << " " << i + plus <<endl << endl;
		if (abs(niz1[i] - niz2[i + plusic]) > 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;
	
*/	
	
	for (int plusic = 0;plusic <= m - n;plusic++) {
		int lo = 0,hi = maks;
		while (lo != hi) {
			int mid = (lo + hi) / 2;
			if (f(mid,plusic)) {
				hi = mid;
			}
			else {
				lo = mid + 1;
			}
		}
		if (lo < minimum) {
			minimum = lo;
		}
	} 
	cout << minimum << endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 132 ms 1016 KB Output is correct
2 Correct 164 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 1104 KB Output is correct
2 Correct 165 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 11 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1056 ms 976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1008 ms 1020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 1156 KB Time limit exceeded
2 Halted 0 ms 0 KB -