Submission #81695

# Submission time Handle Problem Language Result Execution time Memory
81695 2018-10-26T08:23:26 Z aminra Cipele (COCI18_cipele) C++14
90 / 90
338 ms 1436 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int MAXN = (int)1e5 + 7;
const int infint = (int)1e9;
const ll inf = (ll)1e18;
int n, m, a[MAXN], b[MAXN];
bool check(ll mid)
{
	if(n <= m)
	{
		int last = m;
		for (int j = n - 1; j >= 0; j--)
		{
			int r = upper_bound(b, b + m, a[j] + mid) - b - 1;
			int l = lower_bound(b, b + m, a[j] - mid) - b;
			if(l > r)
				return 0;
			if(l > last - 1)
				return 0;
			last = min(r, last - 1);
		}
		return 1;
	}
	else
	{
		int last = n;
		for (int j = m - 1; j >= 0; j--)
		{
			int r = upper_bound(a, a + n, b[j] + mid) - a - 1;
			int l = lower_bound(a, a + n, b[j] - mid) - a;
			if(l > r)
				return 0;
			if(l > last - 1)
				return 0;
			last = min(r, last - 1);	
		}
		return 1;
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	sort(a, a + n);
	sort(b, b + m);
	/*for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	cout << endl;
	for (int i = 0; i < m; i++)
		cout << b[i] << " ";
	cout << endl;*/
	ll l = -1, r = infint + 1;
	while(r - l > 1)
	{
		ll mid = (l + r) >> 1;
		if(check(mid))
			r = mid;
		else
			l = mid;
	}
	cout << r;
}
# Verdict Execution time Memory Grader output
1 Correct 301 ms 1164 KB Output is correct
2 Correct 320 ms 1268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 1344 KB Output is correct
2 Correct 338 ms 1436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1436 KB Output is correct
2 Correct 10 ms 1436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1436 KB Output is correct
2 Correct 10 ms 1436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1436 KB Output is correct
2 Correct 10 ms 1436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1436 KB Output is correct
2 Correct 10 ms 1436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1436 KB Output is correct
2 Correct 10 ms 1436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 1436 KB Output is correct
2 Correct 136 ms 1436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 1436 KB Output is correct
2 Correct 183 ms 1436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 1436 KB Output is correct
2 Correct 202 ms 1436 KB Output is correct