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;
int main()
{
int n;
cin >> n;
vector<pair<int, int>> nec;
vector<int> ini;
for(int i = 0; i < n+1; ++i)
{
int a;
cin >> a;
nec.push_back({a, i});
}
for(int i = 0; i < n; ++i)
{
int a;
cin >> a;
ini.push_back(a);
}
sort(nec.begin(), nec.end());
sort(ini.begin(), ini.end());
int odpp[n+1];
int odpk[n+1];
int ret[n+1];
odpp[0] = max(nec[0].first - ini[0], 0);
odpk[n-1] = max(nec[n].first - ini[n-1], 0);
for(int i = 1; i < n; ++i)
odpp[i] = max(odpp[i-1], max(nec[i].first - ini[i], 0));
for(int i = n-2; i >= 0; --i)
odpk[i] = max(odpk[i+1], max(nec[i+1].first - ini[i], 0));
ret[nec[0].second] = odpk[0];
ret[nec[n].second] = odpp[n-1];
for(int i = 1; i < n; ++i)
ret[nec[i].second] = max(odpp[i-1], odpk[i]);
for(int i = 0; i < n+1; ++i)
cout << ret[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... |