///made by : Mr_Ph :D
#include<bits/stdc++.h>
#include<unordered_map>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
const double PI=acos(-1.0);
const ll mod=(ll)1e9+7;
//int a1[4] = {0, 0, 1, -1};
//int b1[4] = {1, -1, 0, 0};
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define lower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define upper(s) transform(s.begin(),s.end(),s.begin(),::toupper)
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
///the end of the defines ;)
void solve()
{
int n,m;
cin>>n>>m;
vi arr(n);
vi brr(m);
ent(arr);
ent(brr);
vector<int>mp(n+1);
sort(all(arr));
sort(all(brr));
int mxdiff=0,ans=0;
if(n==m)
{
for(int i=0;i<n;i++)
mxdiff=max(abs(arr[i]-brr[i]),mxdiff);
cout<<mxdiff<<endl;
}
else if(n>m)
{
for(int i=0; i<m; i++)
{
int mndiff=INT_MAX;
for(int k=i; k<n; k++)
if(!mp[k])
mndiff=min(mndiff,abs(brr[i]-arr[k]));
for(int k=i; k<n; k++)
{
if(abs(arr[k]-brr[i])==mndiff&&!mp[k])
{
mp[k]++;
break;
}
}
ans=max(ans,mndiff);
}
cout<<ans<<endl;
}
else
{
for(int i=0; i<n; i++)
{
int mndiff=INT_MAX;
for(int k=i; k<m; k++)
if(!mp[k])
mndiff=min(mndiff,abs(arr[i]-brr[k]));
for(int k=i; k<n; k++)
{
if(abs(brr[k]-arr[i])==mndiff&&!mp[k])
{
mp[k]++;
break;
}
}
ans=max(ans,mndiff);
}
cout<<ans<<endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
//freopen("window.in","r",stdin);
//freopen("output.txt","w",stdout);
int t=1;//int st;
//cin>>t;//cin>>st;
while(t--)
solve();
}
Compilation message
cipele.cpp: In function 'void solve()':
cipele.cpp:18:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | #define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
| ~^~~~~~~~~~~
cipele.cpp:29:5: note: in expansion of macro 'ent'
29 | ent(arr);
| ^~~
cipele.cpp:18:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | #define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
| ~^~~~~~~~~~~
cipele.cpp:30:5: note: in expansion of macro 'ent'
30 | ent(brr);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
1484 KB |
Output is correct |
2 |
Correct |
40 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
1360 KB |
Output is correct |
2 |
Correct |
41 ms |
1352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
25 ms |
372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
19 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1079 ms |
1144 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
1220 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1091 ms |
1068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |