Submission #894309

# Submission time Handle Problem Language Result Execution time Memory
894309 2023-12-28T04:35:09 Z vjudge1 Cipele (COCI18_cipele) C++11
90 / 90
31 ms 2020 KB
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e5 + 10;
const ll mod = 1e9 + 7;

ll um(ll a, ll b){
	return ((1LL * a * b) % mod + mod) % mod;
}
ll subr(ll a, ll b){
	return ((1LL * a - b) % mod + mod) % mod;
}
/*
	Восемь восемьсот пять пять пять
	три пять три пять
	Проще кому то позвонить
	чем у кого-то деньги занимать
*/
ll a[N], b[N], n, m;
bool check(ll x){
	if(n <= m){
		ll j = 0;
		for(ll i = 0; i < n; i++){
			while(j < m){
				if(abs(b[j] - a[i]) <= x) break;
				else j++;
			}
			if(j < m && abs(b[j] - a[i]) <= x) j++;
			else return false;
		}
	} else{
		ll j = 0;
		for(ll i = 0; i < m; i++){
			while(j < n){
				if(abs(a[j] - b[i]) <= x) break;
				else j++;
			}
			if(j < n && abs(a[j] - b[i]) <= x) j++;
			else return false;
		}
	}
	return true;
}
int main() {
	ios::sync_with_stdio(false);
  	cin.tie(NULL);
  	cin >> n >> m;
  	for(ll i = 0; i < n; i++){
  		cin >> a[i];
  	}
  	for(ll i = 0; i < m; i++){
  		cin >> b[i];
  	}
  	sort(a, a + n);
  	sort(b, b + m);
  	ll l = -1, r = 1e10;
  	while(r - l > 1){
  		ll mid = (r + l) / 2;
  		if(check(mid)) r = mid;
  		else l = mid;
  	}
  	cout << r;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1884 KB Output is correct
2 Correct 30 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1884 KB Output is correct
2 Correct 31 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1628 KB Output is correct
2 Correct 19 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1856 KB Output is correct
2 Correct 15 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1624 KB Output is correct
2 Correct 29 ms 2020 KB Output is correct