제출 #1086784

#제출 시각아이디문제언어결과실행 시간메모리
1086784IcelastJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
68 ms10872 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; void solve(){ int n; cin >> n; vector<pair<int, int>> a(n+2); vector<int> b(n+1); for(int i = 1; i <= n+1; i++){ cin >> a[i].first; a[i].second = i; } for(int i = 1; i <= n; i++){ cin >> b[i]; } sort(a.begin()+1, a.end(), greater<pair<int, int>>()); sort(b.begin()+1, b.end(), greater<int>()); vector<int> pf(n+3, 0), sf(n+3, 0); for(int i = 1; i <= n; i++){ pf[i] = max(pf[i-1], max(0, a[i].first-b[i])); } for(int i = n+1; i >= 2; i--){ sf[i] = max(sf[i+1], max(0, a[i].first-b[i-1])); } vector<int> ans(n+2); for(int i = 1; i <= n+1; i++){ ans[a[i].second] = max(pf[i-1], sf[i+1]); } for(int i = 1; i <= n+1; i++){ cout << ans[i] << " "; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...