This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//君の手を握ってしまったら
//孤独を知らないこの街には
//もう二度と帰ってくることはできないのでしょう
//君が手を差し伸べた 光で影が生まれる
//歌って聞かせて この話の続き
//連れて行って見たことない星まで
//さユリ - 花の塔
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define starburst ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
void solve(){
int n, t = 0; cin >> n;
vector<pii> a(n + 1, pii(0, 0));
vector<int> b(n), ns(n), s(n);
for(auto &[x, y]:a) cin >> x, y = t++;
for(auto &x:b) cin >> x;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
for(int i = 0; i < n; ++i){
ns[i] = max(0ll, a[i].ff - b[i]);
s[i] = max(0ll, a[i + 1].ff - b[i]);
}
for(int i = 1; i < n; ++i){
int j = n - i - 1;
ns[i] = max(ns[i - 1], ns[i]);
s[j] = max(s[j], s[j + 1]);
}
for(int i = 0; i <= n; ++i){
int ans = 0;
if(i != 0) ans = max(ans, ns[i - 1]);
if(i != n) ans = max(ans, s[i]);
a[i].ff = ans;
}
sort(a.begin(), a.end(), [](pii a, pii b){return a.ss < b.ss;});
for(int i = 0; i <= n; ++i){
cout << a[i].ff << " \n"[i == n];
}
}
signed main(){
starburst
int t = 1; //cin >> t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |