Submission #762951

#TimeUsernameProblemLanguageResultExecution timeMemory
762951giaminh2211Just Long Neckties (JOI20_ho_t1)C++14
100 / 100
80 ms6988 KiB
#include<bits/stdc++.h> #define fn(n) for(int i=1; i<=n; i++) #define v first #define s second using namespace std; using ll=long long; int n; pair<int, int> a[200002]; int c[200002]; int res[200002]; int f[200002]; int s[200002]; void nhap(){ cin >> n; for(int i=1; i<=n+1; i++){ cin >> a[i].v; a[i].s=i; } fn(n) cin >> c[i]; sort(a+1, a+n+2); sort(c+1, c+n+1); } void solve(){ for(int i=1; i<=n; i++){ f[i]=max(f[i-1], max(a[i].v-c[i], 0)); } for(int i=n; i>=1; i--){ s[i]=max(s[i+1], max(a[i+1].v-c[i], 0)); } for(int i=1; i<=n+1; i++){ res[a[i].s]=max(f[i-1], s[i]); } for (int i=1; i<=n+1; i++) cout << res[i] << ' '; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); nhap(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...