Submission #146961

# Submission time Handle Problem Language Result Execution time Memory
146961 2019-08-26T20:55:15 Z albino_ojuz Cipele (COCI18_cipele) C++14
27 / 90
165 ms 2952 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

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

int main () {

	cin >> n >> m;
	for (int i = 0;i < n;i++) {
		cin >> niz1[i];
		if (niz1[i] > maks) {
			maks = niz1[i];
		}
	}
	for (int i = 0;i < m;i++) {
		cin >> niz2[i];
		if (niz2[i] > maks) {
			maks = niz2[i];
		}
	}
	sort(niz1,niz1 + n);
	sort(niz2,niz2 + m);
	
	if (n > m) {
		for (int 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 < m;i++) {
		cout << niz2[i] << " ";
	}cout << endl;
*/	
//									prvi je manji prvi je manji prvi je manji prvi je manji
	int cnt = 0;
	int lo = 0, hi = maks;
	while (lo != hi) {
		cnt++;
		if (cnt > 1000) {
			break;
		}
		int zas = 0;
		int mid = (lo + hi) / 2;
		int plusic = 0;
		for (int 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 (int 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 133 ms 1144 KB Output is correct
2 Correct 165 ms 2952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 1144 KB Output is correct
2 Correct 164 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 10 ms 380 KB Output is 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 7 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 132 ms 888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 145 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 128 ms 932 KB Output isn't correct
2 Halted 0 ms 0 KB -