#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
vector<int>R,L,nR;
int required;
int dp[3003][3003];
int solve(int i,int taken)
{
//cout<<i<<" "<<taken<<endl;
if(taken == 0) return 0;
if(taken - (L.size()-i)>0)return 1e9;
if(i==L.size())return 1e9;
if(dp[i][taken]!=-1)return dp[i][taken];
int ret;
ret = solve(i+1,taken);
int idx1 = lower_bound(R.begin(),R.end(),L[i])-R.begin();
int idx2 = lower_bound(nR.begin(),nR.end(),L[i]*-1)-nR.begin();
int idx;
if(idx1==R.size())idx1--;
if(idx2==nR.size())idx2--;
if( abs((L[i]*-1) - nR[idx2]) < abs((L[i]) - R[idx1]) )
idx = R.size()-idx2-1;
else
idx = idx1;
int ans=abs(L[i]-R[idx]);
vector<int>x,y;
x=R;
y=nR;
R.erase(R.begin()+idx);
nR.erase(nR.begin()+(nR.size()-idx-1));
ret = min(ret,max(ans,solve(i+1,taken-1)));
R=x;
nR=y;
return dp[i][taken] = ret;
}
main()
{
memset(dp,-1,sizeof dp);
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
L.push_back(x);
}
for(int i=0;i<m;i++)
{
int x;
cin>>x;
R.push_back(x);
}
if(n>m)
{
swap(m,n);
swap(L,R);
}
required = n;
for(int i=0;i<R.size();i++)nR.push_back(R[i]*-1);
sort(L.begin(),L.end());
sort(R.begin(),R.end());
sort(nR.begin(),nR.end());
int ans = 0;
cout<<solve(0,required)<<endl;
}
Compilation message
cipele.cpp: In function 'long long int solve(long long int, long long int)':
cipele.cpp:15:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | if(i==L.size())return 1e9;
| ~^~~~~~~~~~
cipele.cpp:22:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if(idx1==R.size())idx1--;
| ~~~~^~~~~~~~~~
cipele.cpp:23:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(idx2==nR.size())idx2--;
| ~~~~^~~~~~~~~~~
cipele.cpp: At global scope:
cipele.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
42 | main()
| ^~~~
cipele.cpp: In function 'int main()':
cipele.cpp:66:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i=0;i<R.size();i++)nR.push_back(R[i]*-1);
| ~^~~~~~~~~
cipele.cpp:71:9: warning: unused variable 'ans' [-Wunused-variable]
71 | int ans = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
216 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
231 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
120372 KB |
Output is correct |
2 |
Incorrect |
164 ms |
236172 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
78688 KB |
Output is correct |
2 |
Incorrect |
144 ms |
236096 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
145 ms |
236028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
147 ms |
236092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
143 ms |
236044 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
226 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
216 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
213 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |