Submission #707874

#TimeUsernameProblemLanguageResultExecution timeMemory
707874Alihan_8Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
108 ms15532 KiB
#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)

ho_t1.cpp: In function 'void IO(std::string)':
ho_t1.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t1.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...