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>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
signed main()
{
fast();
int n;
cin >> n;
vector<in> a(n+2);
vector<int> b(n+1);
for(int i = 1; i <= n+1; i++)
{
cin >> a[i].f;
a[i].s = i;
}
sort(a.begin(), a.end());
for(int i = 1; i <= n; i++)
cin >> b[i];
sort(b.begin(), b.end());
vector<int> c(n+2);
vector<int> pref_max(n+1);
vector<int> suff_max(n+3);
pref_max[0] = 0;
suff_max[n+2] = 0;
for(int i = 1; i <= n; i++)
pref_max[i] = max(pref_max[i-1], a[i].f-b[i]);
for(int i = n+1; i >= 2; i--)
suff_max[i] = max(suff_max[i+1], a[i].f-b[i-1]);
for(int i = 1; i <= n+1; i++)
c[a[i].s] = max(pref_max[i-1], suff_max[i+1]);
for(int i = 1; i <= n+1; i++)
cout << c[i] << " ";
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... |