#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define ub(a,b) upper_bound(a.begin(),a.end(),b)-a.begin();
#define lb(a,b) lower_bound(a.begin(),a.end(),b)-a.begin();
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define sz(x) x.size()
#define T pair<double,string>
using namespace std;
const int mxn=2e5+5;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m;cin>>n>>m;
int s[n+1]={0},f[m+1]={0};
for(int i=1;i<=n;i++)cin>>s[i];for(int i=1;i<=m;i++)cin>>f[i];
ll l=0,r=1e12+1;
int lr[n+1]={0};
while(l<r){
ll k=(l+r)>>1;
int idx=1;memset(lr,0,sizeof lr);
for(int i=1;i<=n;i++){
while(idx<=m&&s[i]-k<=f[idx]&&f[idx]<=s[i])idx++,lr[i]=1;
while(idx<=m&&s[i]<=f[idx]&&f[idx]<=s[i]+k&&lr[i]!=1)idx++,lr[i]=2;
}if(idx!=m+1)l=k+1;
else r=k;
}//if(l==1e12+1){cout<<-1;return 0;}
if(f[m]<=s[1])cout<<s[1]-f[1]<<'\n'<<'L';
else if(s[1]<=f[1])cout<<f[m]-s[1]<<'\n'<<'R';
else cout<<-1;
return 0;
/*memset(lr,0,sizeof lr);int idx=1;
for(int i=1;i<=n;i++){
while(idx<=m&&s[i]-l<=f[idx]&&f[idx]<=s[i])idx++,lr[i]=1;
while(idx<=m&&s[i]<=f[idx]&&f[idx]<=s[i]+l&&lr[i]!=1)idx++,lr[i]=2;
}cout<<l<<'\n';
for(int i=1;i<=n;i++)cout<<(lr[i]==1?"L":"R");*/
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:21:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
21 | for(int i=1;i<=n;i++)cin>>s[i];for(int i=1;i<=m;i++)cin>>f[i];
| ^~~
Main.cpp:21:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
21 | for(int i=1;i<=n;i++)cin>>s[i];for(int i=1;i<=m;i++)cin>>f[i];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
User solution is worse than jury's solution |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Correct |
2 |
Correct |
6 ms |
780 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
7 ms |
1628 KB |
Correct |
5 |
Correct |
7 ms |
1628 KB |
Correct |
6 |
Correct |
0 ms |
344 KB |
Correct |
7 |
Correct |
0 ms |
344 KB |
Correct |
8 |
Correct |
2 ms |
604 KB |
Correct |
9 |
Correct |
0 ms |
452 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
User solution is worse than jury's solution |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
User solution is worse than jury's solution |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
User solution is worse than jury's solution |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
User solution is worse than jury's solution |
2 |
Halted |
0 ms |
0 KB |
- |