Submission #201902

#TimeUsernameProblemLanguageResultExecution timeMemory
201902Osama_AlkhodairyJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
159 ms7008 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long int n; vector <pair <int, int> > a; vector <int> b; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; a.resize(n + 1); for(int i = 0 ; i < n + 1 ; i++){ cin >> a[i].first; a[i].second = i; } b.resize(n); for(auto &i : b) cin >> i; sort(a.begin(), a.end()); sort(b.begin(), b.end()); vector <int> pref(n), suff(n); for(int i = 0 ; i < n ; i++){ if(i > 0) pref[i] = pref[i - 1]; pref[i] = max(pref[i], a[i].first - b[i]); } for(int i = n - 1 ; i >= 0 ; i--){ if(i < n - 1) suff[i] = suff[i + 1]; suff[i] = max(suff[i], a[i + 1].first - b[i]); } vector <int> ans(n + 1); for(int i = 0 ; i < n + 1 ; i++){ ans[a[i].second] = max((i > 0 ? pref[i - 1] : 0), (i < n ? suff[i] : 0)); } for(auto &i : ans) cout << i << " "; cout << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...