Submission #855724

# Submission time Handle Problem Language Result Execution time Memory
855724 2023-10-01T17:13:53 Z vjudge1 Cipele (COCI18_cipele) C++17
90 / 90
44 ms 1884 KB
#include <bits/stdc++.h>
using namespace std;
#define sp << " " << 
#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define all(x) x.begin()+1,x.end()
const int N = 4e5+1;


void solve() {
	int n,m;
	cin >> n >> m;
	vi a(n+1),b(m+1);
	F(i,n) cin >> a[i];
	F(i,m) cin >> b[i];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	if (a.size() > b.size()) swap(a,b),swap(n,m);
	int l = 0;
	int r = 1e9;
	while (l<=r) {
		int x = (l+r) >> 1;
		int ptr2 = 1;
		stack<int> s;
		int fl = 1;
		for (int i=1;i<=n;i++) {
			while (ptr2<=m && (s.empty() || s.top() < a[i]-x)) s.push(b[ptr2++]);
			if (!s.empty() && s.top() >= a[i]-x && s.top() <= a[i]+x) {
				//cout << x sp s.top() sp a[i] << endl;
				while (!s.empty()) s.pop();
				continue;
			}
			fl = 0;
			break;
		}
		//cout << x sp fl << endl;
		if (fl) r = x-1;
		else l = x+1;
	}
	cout << l << endl;
}     	
                                
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}

# Verdict Execution time Memory Grader output
1 Correct 27 ms 1884 KB Output is correct
2 Correct 40 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 1884 KB Output is correct
2 Correct 40 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 3 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 3 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 1628 KB Output is correct
2 Correct 25 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1628 KB Output is correct
2 Correct 22 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 1716 KB Output is correct
2 Correct 35 ms 1628 KB Output is correct