Submission #146963

# Submission time Handle Problem Language Result Execution time Memory
146963 2019-08-26T21:01:26 Z albino_ojuz Cipele (COCI18_cipele) C++14
18 / 90
167 ms 2000 KB
#include <bits/stdc++.h>

using namespace std;

const long long N = 1e5+5;

long long n,m;
long long niz1[N],niz2[N];
long long maks,mini = 1e9+7;

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 (long long i = 0;i < n;i++) {
		cout << niz1[i] << " ";
	}cout << endl;
	
	for (long long i = 0;i < m;i++) {
		cout << niz2[i] << " ";
	}cout << endl;
*/	
//									prvi je manji prvi je manji prvi je manji prvi je manji
	long long cnt = 0;
	long long lo = mini, hi = maks;
	while (lo != hi) {
		cnt++;
		if (cnt > 1000) {
			break;
		}
		long long zas = 0;
		long long mid = (lo + hi) / 2;
		long long plusic = 0;
		for (long long i = 0;i < n;i++) {
		
			while(abs(niz1[i] - niz2[i + plusic]) > mid) {
				plusic++;
				if (i + plusic >= n) {
					zas = 1;
					break;
				}
			}
			if (zas == 1) {
				break;
			}
		}
		
		for (long long i = 0; i < n - plusic; i++) {
			if (abs(niz1[i] - niz2[i + plusic]) > mid) {
				zas = 1;
				break;
			}
		}
		
		if (zas == 0) {
			hi = mid;
		}
		else {
			lo = mid + 1;
		}
	}
	
	cout << lo <<endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 136 ms 1872 KB Output is correct
2 Correct 166 ms 2000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 1920 KB Output is correct
2 Correct 167 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 420 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 135 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 148 ms 1784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 131 ms 1604 KB Output isn't correct
2 Halted 0 ms 0 KB -