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>
#define mod 1000000007
//define int long long
// https://www.youtube.com/watch?v=t5GDacP_2pQ
using namespace std;
ifstream in ("film.in");
ofstream out ("film.out");
int pow (int a, int b)
{
int rez = 1;
while (b)
{
if (b&1)
rez = (rez * a) % mod;
a = (a * a) % mod;
b>>=1;
}
return rez;
}
pair <int, int> a[200002];
int b[200001], n;
int ans[200001];
int st[200001];
int dr[200001];
void solve ()
{
cin >> n;
for (int i = 1;i<=n+1;++i)
{
cin >> a[i].first;
a[i].second = i;
}
for (int i = 1;i<=n;++i)
cin >> b[i];
sort(a + 1, a + n + 2);
sort(b + 1, b + n + 1);
b[n+1] = a[n+1].first;
for (int i = 1;i<=n;++i)
st[i] = max(st[i-1], max(0, a[i].first - b[i]));
dr[n+1] = 0;
for (int i = n;i>=1;--i)
dr[i] = max(dr[i+1], max(0, a[i+1].first - b[i]));
for (int i = n + 1;i>=1;--i)
ans[a[i].second] = max(dr[i], st[i-1]);
for (int i = 1;i<=n+1;++i)
cout << ans[i] << ' ';
cout << '\n';
}
main ()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while (t--)
solve();
}
Compilation message (stderr)
ho_t2.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main ()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |