제출 #256950

#제출 시각아이디문제언어결과실행 시간메모리
256950akatJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
118 ms10104 KiB
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 2; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, i; pair<int,int> p[N]; cin>>n; for(i = 0; i < n + 1; i++) { cin>>p[i].first; p[i].second = i; } int b[N]; for(i = 0; i < n; i++) cin>>b[i]; sort(p, p + n + 1); sort(b, b + n); int m[N]; m[0] = max(p[0].first - b[0], 0); for(i = 1; i < n; i++) m[i] = max(m[i-1], p[i].first - b[i]); int ans[N], cm = 0; for(i = n; i > 0; i--) { ans[p[i].second] = max(m[i-1], cm); cm = max(cm, p[i].first - b[i-1]); } ans[p[i].second] = cm; for(i = 0; i < n + 1; i++) cout<<ans[i]<<"\n "[i!=n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...