Submission #672180

#TimeUsernameProblemLanguageResultExecution timeMemory
672180Charizard2021Cipele (COCI18_cipele)C++17
18 / 90
88 ms3748 KiB
#include<bits/stdc++.h> using namespace std; int main(){ long long n, m; cin >> n >> m; vector<long long> l(n); vector<long long> r(m); for(int i = 0; i < n; i++){ cin >> l[i]; } for(int i = 0; i < m; i++){ cin >> r[i]; } sort(l.begin(), l.end()); sort(r.begin(), r.end()); if(n > m){ swap(l, r); swap(n, m); } bool visited[m]; long long ans = 0; memset(visited, false, sizeof(visited)); for(long long i = 0;i < n; i++){ long long lo = 0; long long hi = m - 1; lo--; while (lo < hi) { long long mid = lo + (hi - lo + 1) / 2; if (r[mid] <= l[i] && !visited[mid]) { lo = mid; } else { hi = mid - 1; } } long long cur_dif = INT_MAX; long long cur = -1; if(lo != -1){ cur_dif = l[i] - r[lo]; cur = lo; } long long lo2 = 0; long long hi2 = m - 1; hi2++; while (lo2 < hi2) { long long mid = lo2 + (hi2 - lo2) / 2; if (r[mid] >= l[i] && !visited[mid]) { hi2 = mid; } else { lo2 = mid + 1; } } if(lo2 != m){ if(cur_dif > abs(l[i] - r[lo2])){ cur_dif = abs(l[i] - r[lo2]); cur = lo2; } } if(cur != -1){ visited[cur] = true; ans = max(ans, cur_dif); } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...