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>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#define jizz ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;
ll ft[200005];
ll bk[200005];
ll b[200005];
ll n;
struct st{
ll loc, v;
};
vector <st> ans;
st a[200005];
bool num(st a, st b){
return a.v<b.v;
}
bool locate(st a, st b){
return a.loc<b.loc;
}
int main() {
scanf("%lld", &n);
for(ll i = 1; i <= n+1; i++) scanf("%lld", &a[i].v),a[i].loc = i;
for(ll i = 1; i <= n; i++) scanf("%lld", b+i);
sort(a+1, a+n+2, num);
sort(b, b+n+1);
for(ll i = 1; i <= n; i++) ft[i]=max(ft[i-1], a[i].v-b[i]);
for(ll i = n; i >= 1; i--) bk[i]=max(bk[i+1], a[i+1].v-b[i]);
for(ll i = 1; i <= n+1; i++){
if(i==1)
ans.push_back({a[i].loc, bk[i]});
else if(i==n+1)
ans.push_back({a[i].loc, ft[i-1]});
else
ans.push_back({a[i].loc, max(ft[i-1], bk[i])});
// printf("%lld %lld\n", ans.back().loc, ans.back().v );
}
sort(ans.begin(), ans.end(), locate);
for(auto i:ans){
printf("%lld ", i.v);
}
return 0;
}
Compilation message (stderr)
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf("%lld", &n);
| ~~~~~^~~~~~~~~~~~
ho_t1.cpp:25:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | for(ll i = 1; i <= n+1; i++) scanf("%lld", &a[i].v),a[i].loc = i;
| ~~~~~^~~~~~~~~~~~~~~~~
ho_t1.cpp:26:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | for(ll i = 1; i <= n; i++) scanf("%lld", b+i);
| ~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |