이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define fn(n) for(int i=1; i<=n; i++)
#define v first
#define s second
using namespace std;
using ll=long long;
int n;
pair<int, int> a[200002];
int c[200002];
int res[200002];
int f[200002];
int s[200002];
void nhap(){
cin >> n;
for(int i=1; i<=n+1; i++){
cin >> a[i].v;
a[i].s=i;
}
fn(n) cin >> c[i];
sort(a+1, a+n+2);
sort(c+1, c+n+1);
}
void solve(){
for(int i=1; i<=n; i++){
f[i]=max(f[i-1], max(a[i].v-c[i], 0));
}
for(int i=n; i>=1; i--){
s[i]=max(s[i+1], max(a[i+1].v-c[i], 0));
}
for(int i=1; i<=n+1; i++){
res[a[i].s]=max(f[i-1], s[i]);
}
for (int i=1; i<=n+1; i++) cout << res[i] << ' ';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
nhap();
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... |