Submission #1114713

#TimeUsernameProblemLanguageResultExecution timeMemory
1114713tkwiatkowskiJust Long Neckties (JOI20_ho_t1)C++17
0 / 100
1 ms336 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin >> n; vector<ll> a(n+1); vector<ll> b(n); vector<ll> pref(n+1, 0); vector<ll> suf(n+1, 0); for (int i = 0; i <= n; i++){ cin >> a[i]; } for (int i = 0; i < n; i++){ cin >> b[i]; } sort(a.begin(), a.end()); sort(b.begin(), b.end()); vector<ll> res(n+1); ll aktual = 0; for (int i = 0; i < n; i++){ // pref czyli jak usuwamy ity elem np. ostatni ll h = a[i] - b[i]; aktual = max(aktual, h); pref[i] = aktual; } res[n] = aktual; aktual = 0; for (int i = n-1; i > 0; i--){ // suf co jak zabierzemy ity elem laczymy na skos ll h = a[i+1] - b[i]; aktual = max<ll>(aktual, h); suf[i] = aktual; } res[0] = aktual; for (int i = 1; i < n; i++){ // zabieramy ity ll h = max<ll>(pref[i-1], suf[i]); res[i] = h; } for (int i = 0; i <= n; i++){ cout << res[i] << ' '; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...