Submission #389880

#TimeUsernameProblemLanguageResultExecution timeMemory
389880vishesh312Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
128 ms10948 KiB
#include "bits/stdc++.h" using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; */ #define all(x) begin(x), end(x) #define sz(x) (int)x.size() using ll = long long; const int mod = 1e9+7; void solve(int tc) { int n; cin >> n; vector<int> b(n); vector<array<int, 2>> a(n+1); for (int i = 0; i < n+1; ++i) { cin >> a[i][0]; a[i][1] = i; } for (auto &x : b) cin >> x; sort(all(a)); sort(all(b)); vector<int> p(n), s(n); p[0] = max(0, a[0][0] - b[0]); s[0] = max(0, a[n][0] - b[n-1]); for (int i = 1; i < n; ++i) { p[i] = max({0, p[i-1], a[i][0] - b[i]}); s[i] = max({0, s[i-1], a[n-i][0] - b[n-1-i]}); } vector<int> ans(n+1); ans[a[0][1]] = max(0, s.back()); for (int i = 1; i < n; ++i) { ans[a[i][1]] = max(p[i-1], s[n-1-i]); } ans[a[n][1]] = max(0, p.back()); for (int i = 0; i < n+1; ++i) cout << ans[i] << " "; cout << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; for (int i = 1; i <= tc; ++i) solve(i); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...