Submission #367195

#TimeUsernameProblemLanguageResultExecution timeMemory
367195piddddgyJust Long Neckties (JOI20_ho_t1)C++11
100 / 100
111 ms13932 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; // #define cerr if(false) cerr #define watch(x) cerr << (#x) << " is " << (x) << endl; #define endl '\n' #define ld long double #define int long long #define pii pair<int, int> #define fi first #define se second #define sz(a) (int)(a).size() #define all(x) (x).begin(), (x).end() const int maxn = 200500; int n; pii a[maxn]; int b[maxn]; int pre[maxn], suf[maxn]; int ans[maxn]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n+1; i++) { cin >> a[i].fi; a[i].se = i; } for(int i = 1; i <= n; i++) { cin >> b[i]; } sort(a+1, a+n+2); sort(b+1, b+n+1); for(int i = 1; i <= n; i++) { int o = max(a[i].fi-b[i], 0LL); pre[i] = max(pre[i-1], o); } for(int i = n; i >= 1; i--) { int o = max(a[i+1].fi-b[i], 0LL); suf[i] = max(suf[i+1], o); } for(int i = 1; i <= n+1; i++) { int val = max(pre[i-1], suf[i]); ans[a[i].se] = val; } for(int i = 1; i <= n+1; i++) { cout << ans[i] << " "; } cout << endl; } /* Did you read the bounds? Did you make typos? Are there edge cases (N=1?) Are array sizes proper? Integer overflow? DS reset properly between test cases? Is using long longs causing TLE? Are you using floating points? */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...