Submission #681748

# Submission time Handle Problem Language Result Execution time Memory
681748 2023-01-14T03:14:04 Z penguin133 Cipele (COCI18_cipele) C++17
90 / 90
38 ms 3620 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
int n, m, L[100005], R[100005];
void solve(){
	cin >> n >> m;
	for(int i=1;i<=n;i++)cin >> L[i];
	for(int i=1;i<=m;i++)cin >> R[i];
	sort(L+1, L+1+n);
	sort(R+1, R+1+m);
	int lo = 0, hi = 2e9, ans = hi + 1;
	while(lo <= hi){
		int mid = (lo + hi) >> 1;
		int in = 1;
		bool die = 0;
		if(n < m){
			for(int i=1;i<=n;i++){
				while(in <= m && L[i] - R[in] > mid)in++;
				if(in == m + 1 || abs(L[i] - R[in]) > mid)die = 1;
				in++;
			}
		}
		else{
			for(int i=1;i<=m;i++){
				while(in <= n && R[i] - L[in] > mid)in++;
				if(in == n + 1 || abs(R[i] - L[in]) > mid)die = 1;
				in++;
			}
		}
		if(die)lo = mid + 1;
		else hi = mid - 1, ans = mid;
	}
	cout << ans;
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

cipele.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 3404 KB Output is correct
2 Correct 37 ms 3600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3620 KB Output is correct
2 Correct 37 ms 3564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2992 KB Output is correct
2 Correct 27 ms 2232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3276 KB Output is correct
2 Correct 18 ms 2472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2968 KB Output is correct
2 Correct 32 ms 3156 KB Output is correct