#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=2e5+5;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
optimise;
int n;
cin>>n;
vector<pair<int,int>> a(n+1);
vector<int> b(n);
for (int i = 0; i < n+1; ++i)
{
cin>>a[i].fi;
a[i].se=i;
}
for (int i = 0; i < n; ++i)
{
cin>>b[i];
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
int pre[n+1];
int suf[n+1];
pre[0]=max(0,a[0].fi-b[0]);
pre[n]=0;
suf[0]=0;
suf[n]=max(0,a[n].fi-b[n-1]);
for (int i = 1; i < n; ++i)
{
pre[i]=max(max(a[i].fi-b[i],0),pre[i-1]);
}
for (int i = n-1; i > 0; --i)
{
suf[i]=max(max(a[i].fi-b[i-1],0),suf[i+1]);
}
vector<int> ans(n+1);
for (int i = 0; i <= n; ++i)
{
cout <<pre[i]<<" "<<suf[i]<<endl;
if(i>0&&i<n) ans[a[i].se]=max(pre[i-1],suf[i+1]);
else if(i==0) ans[a[i].se]=suf[i+1];
else ans[a[i].se]=pre[i-1];
}
for (int i = 0; i <= n; ++i)
{
cout <<ans[i]<<" ";
}cout <<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |