This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 2e5 + 1;
int a[N + 1], b[N + 1], id[N + 1], dp[N + 1], res[N + 1], n;
void read()
{
cin >> n;
for (int i = 1; i <= n + 1; ++ i)
{
cin >> a[i];
id[i] = i;
}
sort(id + 1, id + n + 2, [&](const int &x, const int &y)
{
return a[x] < a[y];
});
sort(a + 1, a + n + 2);
for (int i = 1; i <= n; ++ i)
{
cin >> b[i];
}
sort(b + 1, b + n + 1);
}
void solve()
{
for (int i = 1; i <= n; ++ i)
{
dp[i] = max(dp[i - 1], max(0, a[i] - b[i]));
}
for (int i = n + 1, k = 0; i >= 1; -- i)
{
res[id[i]] = max(dp[i - 1], k);
k = max(k, max(0, a[i] - b[i - 1]));
}
for (int i = 1; i <= n + 1; ++ i)
{
cout << res[i] << ' ';
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message (stderr)
ho_t1.cpp: In function 'int main()':
ho_t1.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |