Submission #147046

# Submission time Handle Problem Language Result Execution time Memory
147046 2019-08-27T10:09:18 Z albino_ojuz Cipele (COCI18_cipele) C++14
27 / 90
1000 ms 1196 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;
		int cnt = 0;
		while (lo != hi) {
			cnt++;
			if (cnt > 1000) break;
			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 130 ms 1128 KB Output is correct
2 Correct 164 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 1196 KB Output is correct
2 Correct 159 ms 1136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 12 ms 404 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 81 ms 432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 376 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 1033 ms 940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 1016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 888 KB Time limit exceeded
2 Halted 0 ms 0 KB -