# pragma GCC optimize ("O3")
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#define MEM 222222
#define sanic ios_base::sync_with_stdio(0)
#define x first
#define y second
#define pf push_front
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
typedef pair<pi, pi> pii;
const ll MOD = 1e18;
const ll INF = 2e9+7;
const long double Pi = 3.141592;
ll gp(ll a, ll b){
return ((a*b)%MOD+MOD)%MOD;
}
ll t,n;
ll b[MEM];
pi a[MEM];
ll ans[MEM], c1[MEM], c2[MEM];
signed main(){
sanic; cin.tie(0); cout.tie(0);
cin >> n;
for(int i=0 ;i<=n; i++){
cin >> a[i].x;
a[i].y = i;
}
for(int i=0; i<n; i++)
cin >> b[i];
sort(a,a+n+1);
sort(b,b+n);
for(int i=0; i<n; i++){
c1[i] = a[i].x-b[i];
c2[i] = a[i+1].x-b[i];
//cout << c1[i] << ' ' << c2[i] << '\n';
}
c1[0] = max(0LL, c1[0]);
c1[n-1] = max(0LL, c1[n-1]);
for(int i=1; i<n; i++)
c1[i] = max(c1[i], c1[i-1]);
for(int i=n-2; i>=0; i--)
c2[i] = max(c2[i], c2[i+1]);
for(int i=0; i<=n; i++){
ll j = a[i].y;
if(!j) ans[j] = max(c2[j], 0LL);
else if(j==n) ans[j] = max(c1[j-1], 0LL);
else ans[j] = max(max(c1[j-1], c2[j]), 0LL);
// << j << ' ' << ans[j] << '\n';
}
for(int i=0; i<=n; i++)
cout << ans[i] << ' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |