이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define sp << " "
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task " "
using namespace std;
struct tmp{
ll id, ans, v;
};
ll n, b[200005];
tmp a[200005];
ll t1[200005], t2[200005];
bool cmp2(tmp x, tmp y){
return x.id<y.id;
}
void sub1(){
ll c, ans;
for(ll i = 1; i <= n+1; i++){
c = 1, ans = -1e18;
for(ll j = 1; j <= n; j++){
if(c==i) c++;
ans=max(ans, max(0ll, a[c].v-b[j]));
c++;
}
a[i].ans = ans;
}
sort(a+1,a+n+2,cmp2);
for(ll i = 1; i <= n+1; i++) cout << a[i].ans sp;
}
void sub2(){
for(ll i = 1; i <= n;i++){
t1[i]=a[i+1].v-b[i];
t2[i]=a[i].v-b[i];
}
// for(ll i = 1; i <= n; i++){
// //cout << max(t1[i], t2[i-1]) sp;
// cout << t1[i] sp << t2[i] << "\n";
// }
for(ll i = 1; i <= n; i++) t2[i]=max(t2[i], t2[i-1]);
for(ll i = n; i >= 1; i--) t1[i]=max(t1[i], t1[i+1]);
for(ll i = 1; i <= n+1; i++){
a[i].ans = max(t1[i], t2[i-1]);
//cout << t1[i] sp << t2[i] << "\n";
}
sort(a+1,a+n+2,cmp2);
for(ll i = 1; i <= n+1; i++) cout << a[i].ans sp;
}
bool cmp(tmp x, tmp y){
return x.v<y.v;
}
int main(){
faster
//freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
cin >> n;
for(ll i = 1; i <= n+1; i++){
cin >> a[i].v;
a[i].id=i;
}
for(ll j = 1; j <= n; j++) cin >> b[j];
sort(a+1,a+n+2, cmp);
sort(b+1,b+n+1);
if(n<=2000){
sub1();
}
else{
sub2();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |