Submission #147085

# Submission time Handle Problem Language Result Execution time Memory
147085 2019-08-27T13:11:01 Z albino_ojuz Cipele (COCI18_cipele) C++14
18 / 90
164 ms 3724 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;
 
int n,m;
int mini,maks;
long long niz1[N],niz2[N];

bool f(int mid) {
	int zas = 0;
	int pom = 0,ad = 0;
	for (int i = 0;i < n;i++) {
		for (int j = i + ad;j < m;j++) {
			if (abs(niz1[i] - niz2[j]) <= mid) {
				//uspio sam uparit
				break;
			}
			if (j == m - 1) {//nisam ga naso uopce
				zas = 1;
			}
			pom++;
		}
		ad = pom;
	}
	if (ad > n - m) return false;
	if (zas == 1) {
		return false;
	}
	return true;
}

int main () {
	
	cin >> n >> m;
	for (int i = 0;i < n;i++) {
		cin >> niz1[i];
		if (niz1[i] > maks) {
			maks = niz1[i];
		}
		if (niz1[i] < mini) {
			mini = niz1[i];
		}
	}
	for (int 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);
	// 											prvi je manji prvi je manji prvi je manji
	if (n > m) {
		for (int i = 0;i < n;i++) {
			swap(niz1[i],niz2[i]);
		}
		swap(n,m);
	}
	
	long long lo = 0, hi = maks;
	while (lo != hi) {
		long long mid = (lo + hi) / 2;
			
		if (f(mid)) {
			hi = mid;
		}
		else {
			lo = mid + 1;
		}
	}
	
	cout << lo << endl; 	
	/*for (int i = 17266842;i < 17276962;i++) {
		if (f(i) != f(i + 1)) {
			cout << i << endl;
		}
	}*/
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 132 ms 3636 KB Output is correct
2 Correct 161 ms 3708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 3724 KB Output is correct
2 Correct 161 ms 3644 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 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 504 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 130 ms 3128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 145 ms 3300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 3020 KB Output isn't correct
2 Halted 0 ms 0 KB -