| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 707874 | Alihan_8 | Just Long Neckties (JOI20_ho_t1) | C++17 | 108 ms | 15532 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>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
bool chmax(int &x, int y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vector <pair<int,int>> p;
vector <int> b(n), res(n+1);
for ( int i = 0; i <= n; i++ ){
int x; cin >> x;
p.pb({x, i});
}
for ( auto &i: b ) cin >> i;
sort(all(b)), sort(all(p));
vector <int> pref(n), suff(n);
for ( int i = 0; i < n; i++ ){
if ( i ) pref[i] = pref[i-1];
chmax(pref[i], p[i].first-b[i]);
}
for ( int i = n-1; i >= 0; i-- ){
if ( i+1 < n ) suff[i] = suff[i+1];
chmax(suff[i], p[i+1].first-b[i]);
}
res[p[0].second] = suff[0];
res[p[n].second] = pref.back();
for ( int i = 1; i < n; i++ ){
res[p[i].second] = max(pref[i-1], suff[i]);
}
for ( auto i: res ) cout << i << ' ';
cout << '\n';
}
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... | ||||
