# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1040030 | MrPavlito | Just Long Neckties (JOI20_ho_t1) | C++17 | 62 ms | 11628 KiB |
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 int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 1e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
signed main()
{
ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--)
{
int n;
cin >> n;
vector<pii>a(n+1);
vector<int>b(n);
for(int i=0; i<=n; i++)
{
cin >> a[i].fi;
a[i].sc = i;
}
for(int i=0; i<n; i++)cin >> b[i];
sort(all(b));
sort(all(a));
vector<int> razlika(n);
for(int i=0; i<n; i++)razlika[i] = a[i+1].fi - b[i];
vector<int> prefmax(n+1,0);
vector<int> sufmax(n+1,0);
for(int i=n-1; i>=0; i--)sufmax[i] = max(sufmax[i+1], razlika[i]);
vector<int> rez(n+1);
rez[a[0].sc] = sufmax[0];
for(int i=1; i<=n; i++)
{
prefmax[i] = max(prefmax[i-1], a[i-1].fi - b[i-1]);
rez[a[i].sc] = max(prefmax[i], sufmax[i]);
}
//for(auto x:prefmax)cout << x << " ";cout <<endl;
//for(auto x:sufmax)cout << x << " ";cout <<endl;
for(auto x:rez)cout << x << " ";cout <<endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |