Submission #385235

#TimeUsernameProblemLanguageResultExecution timeMemory
385235Aryan_RainaJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
119 ms15512 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define ar array const int INF = 1e15; const int MOD = 1e9+7; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; vector<ar<int,2>> a(n+1); vector<int> b(n); for (int i = 0; i <= n; i++) { cin>>a[i][0]; a[i][1] = i; } for (int &i : b) cin>>i; sort(a.begin(), a.end()); sort(b.begin(), b.end()); int pf[n], sf[n]; pf[0] = a[0][0]-b[0]; for (int i = 1; i < n; i++) pf[i] = max(pf[i-1], a[i][0]-b[i]); sf[n-1] = a[n][0]-b[n-1]; for (int i = n-2; i >= 0; --i) sf[i] = max(sf[i+1], a[i+1][0]-b[i]); vector<int> ans(n+1); ans[a[0][1]] = sf[0]; for (int i = 1; i < n; i++) { ans[a[i][1]] = max(sf[i], pf[i-1]); } ans[a[n][1]] = pf[n-1]; for (int i : ans) cout<<i<<" "; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...