Submission #130970

# Submission time Handle Problem Language Result Execution time Memory
130970 2019-07-16T10:30:07 Z Lightning Cipele (COCI18_cipele) C++14
90 / 90
53 ms 2972 KB
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

const int N = 2e5;
const int INF = 1e9;

int n, m, a[N], b[N];

bool check(int x) {
	int pos = 1;
	for(int i = 1; i <= n; ++i) {
		while(pos <= m && abs(a[i] - b[pos]) > x) {
			++pos;		
		}
		if(pos <= m && abs(a[i] - b[pos]) <= x) {
			++pos;
		}	
		else {
			return 0;
		}
	}
	return 1;		
}

int main () {
	ios_base :: sync_with_stdio(false);
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);	
	for(int i = 1; i <= m; ++i) {
		cin >> b[i];
	}
	sort(b + 1, b + m + 1);
	if(n > m) {
		for(int i = 1; i <= n; ++i) {
			swap(a[i], b[i]);
		}
		swap(n, m);
	}
	int l = 0, r = INF;
	while(l < r) {
		int mid = (l + r) / 2;
		if(check(mid)) r = mid;
		else l = mid + 1;
	}
	cout << r;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2680 KB Output is correct
2 Correct 52 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2936 KB Output is correct
2 Correct 53 ms 2972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 2424 KB Output is correct
2 Correct 32 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2680 KB Output is correct
2 Correct 28 ms 2108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2424 KB Output is correct
2 Correct 48 ms 2552 KB Output is correct