Submission #365249

#TimeUsernameProblemLanguageResultExecution timeMemory
365249MeloricJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
122 ms15720 KiB
#include <bits/stdc++.h> #define pb push_back #define int int64_t #define pii pair<int, int> #define X first #define Y second #define all(x) (x).begin(),(x).end() using namespace std; const int inf = 1e18; void p(vector<int>& A){ //for(auto e : A)cout << e << ' '; //cout << '\n'; } void solve(){ int n; cin >> n; vector<pii>A(n+1); vector<int>B(n); for(int i = 0; i< n+1; i++)cin >> A[i].X, A[i].Y = i; for(int i = 0; i< n; i++)cin >> B[i]; sort(all(A)); sort(all(B)); vector<int> pref(n), suff(n); for(int i = 0; i< n; i++)pref[i] = max(A[i].X-B[i], 0l); for(int i = 0; i< n; i++)suff[i] = max(A[i+1].X-B[i], 0l); p(pref);p(suff); for(int i = 1; i< n; i++)pref[i] = max(pref[i], pref[i-1]); for(int i = n-2; i>=0; i--)suff[i] = max(suff[i], suff[i+1]); p(pref);p(suff); vector<int> ans(n+1); ans[A[0].Y] = suff[0]; ans[A[n].Y] = pref[n-1]; for(int i = 1; i< n; i++){ ans[A[i].Y] = max(pref[i-1], suff[i]); //cout << A[i].Y << ' '; } //cout << '\n'; for(auto e : ans)cout << e << ' '; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin >> t; while(t--)solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...