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 endl '\n'
using namespace std;
const int MAXN = 2e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long n, a[MAXN], b[MAXN];
void read()
{
cin >> n;
for (int i = 1; i <= n + 1; ++ i)
cin >> a[i];
for (int i = 1; i <= n; ++ i)
cin >> b[i];
sort(a+1, a+n+2);
sort(b+1, b+n+1);
}
long long dp0[MAXN], dp1[MAXN];
void solve()
{
for (int i = 1; i <= n; ++ i)
{
dp0[i] = dp0[i-1];
dp0[i] = max(dp0[i], max(1LL * 0, a[i] - b[i]));
//cout << dp0[i] << " ";
}
// cout << endl;
for (int i = n+1; i >= 1; -- i)
{
dp1[i] = dp1[i+1];
dp1[i] = max(dp1[i], max(1LL * 0, a[i] - b[i-1]));
}
for (int i = 1; i <= n+1; ++ i)
{
cout << max(dp0[i-1], dp1[i+1]) << " ";
}
cout << endl;
}
int main()
{
speed();
read();
solve();
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... |