이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<ll> a(n+1), b(n);
vector<pair<ll, int>> aa;
for(int i = 0; i <= n; i++){
ll x; cin >> x;
a[i] = x;
aa.pb({x, i});
}
for(ll &x: b) cin >> x;
sort(a.begin(), a.end());
sort(aa.begin(), aa.end());
sort(b.begin(), b.end());
vector<ll> dpa(n, 0), dpb(n, 0);
dpa[0] = max(a[0]-b[0], 0LL);
dpb[n-1] = max(a[n] - b[n-1], 0LL);
for(int i = 1; i < n; i++) dpa[i] = max(dpa[i-1], max(a[i] - b[i], 0LL));
for(int i = n-2; i >= 0; i--) dpb[i] = max(dpb[i+1], max(a[i+1] - b[i], 0LL));
for(int i = 0; i <= n; i++){
aa[i].f = i;
ll tmp = aa[i].f;
aa[i].f = aa[i].sc;
aa[i].sc = tmp;
}
sort(aa.begin(), aa.end());
for(int i = 0; i <= n; i++){
int in = aa[i].sc;
ll ans = 0;
if(in > 0) ans = max(ans, dpa[in-1]);
if(in < n) ans = max(ans, dpb[in]);
cout << ans << " ";
}
cout << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |