#include <bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<class T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long
#define sz(x) (int)(x).size()
#define all(x) x.begin() , x.end()
void Sonic(string name = "") {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if(sz(name)){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
int xd[] = {0, 0, 1, -1, 1, 1, -1, -1};
int yd[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int mxn = 1005;
int n,m;
bool valid(int ugl, vector<int>&ls, vector<int>&rs){
int ptl = 0, ptr = 0;
int paired = 0;
while(ptl<n&&ptr<m){
if(abs(ls[ptl]-rs[ptr])<=ugl){
paired++,ptl++,ptr++;
}else {
ptr++;
}
}
if(paired!=n)return false;
else return true;
}
void run_test_case(){
cin>>n>>m;
vector<int>l(n),r(m);
for(int i = 0; i < n; i++)cin>>l[i];
for(int i = 0; i < m; i++)cin>>r[i];
sort(all(l));
sort(all(r));
if(n>m){
swap(n,m);
swap(l,r);
}
int ans = 1e5;
int left = 0, right = 1e9;
while(left<=right){
int mid = (left+right)/2;
if(valid(mid,l,r)){
ans = mid;
right = mid-1;
}else left = mid+1;
}
cout<<ans;
}
int main(){
Sonic();
int T = 1;
//cin>>T;
while(T--){
run_test_case();
}
return 0;
}
Compilation message
cipele.cpp: In function 'void Sonic(std::string)':
cipele.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | freopen((name+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cipele.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen((name+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1108 KB |
Output is correct |
2 |
Correct |
47 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
1108 KB |
Output is correct |
2 |
Correct |
46 ms |
3016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
356 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
948 KB |
Output is correct |
2 |
Correct |
33 ms |
1796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
1024 KB |
Output is correct |
2 |
Correct |
28 ms |
1932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
932 KB |
Output is correct |
2 |
Correct |
40 ms |
2388 KB |
Output is correct |