이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2e5+5;
int a[MAX];
int b[MAX];
int maxpref[MAX],maxsuf[MAX];
int ans[MAX];
int c[MAX];
bool cmp(int i,int j){
return a[i]<a[j];
}
int32_t main()
{
BOOST;
int n;
cin>>n;
for (int i=1;i<=n+1;i++)cin>>a[i];
for (int i=1;i<=n;i++)cin>>b[i];
sort(b+1,b+n+1);
for (int i=1;i<=n+1;i++)c[i]=i;
sort(c+1,c+n+2,cmp);
vi c1,c2;
for (int i=1;i<=n;i++)c2.pb(b[i]);
for (int i=1;i<=n;i++)c1.pb(a[i]);
for (int i=1;i<=n;i++){
int id=c[i];
maxpref[i]=max(maxpref[i-1],a[id]-b[i]);
}
for (int i=n;i>=1;i--){
int id=c[i+1];
//cout<<"XD "<<id<<" "<<i<<"\n";
maxsuf[i]=max(maxsuf[i+1],a[id]-b[i]);
//cout<<"AFTER "<<i<<" "<<maxsuf[i]<<"\n";
}
for (int wywal=1;wywal<=n+1;wywal++){
int ilebiore=n-(wywal-1);
ans[c[wywal]]=max(maxpref[wywal-1],maxsuf[n-ilebiore+1]);
}
for (int i=1;i<=n+1;i++)cout<<ans[i]<<" ";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |