This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |