Submission #532110

#TimeUsernameProblemLanguageResultExecution timeMemory
532110scottchouJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
109 ms10056 KiB
#include<iostream> #include<algorithm> #include<vector> using namespace std; int const N = 200005; int b[N], premax[N]; typedef pair<int, int> pii; pii a[N]; int ans[N]; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i = 0; i <= n; i++){ cin >> a[i].first; a[i].second = i; } for(int i = 0; i < n; i++){ cin >> b[i]; } sort(b, b + n); sort(a, a + n + 1); premax[0] = a[0].first - b[0]; for(int i = 1; i < n; i++){ premax[i] = max(premax[i - 1], a[i].first - b[i]); } int prem = 0; for(int i = n; i >= 0; i--){ prem = max(prem, a[i + 1].first - b[i]); int maxn = 0; if(i == 0){ maxn = prem; }else{ maxn = max(prem, premax[i - 1]); } ans[a[i].second] = maxn; } for(int i = 0; i <= n; i++){ cout << ans[i] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...