Submission #1188001

#TimeUsernameProblemLanguageResultExecution timeMemory
1188001zeroesandonesJust Long Neckties (JOI20_ho_t1)C++20
0 / 100
0 ms320 KiB
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> vi; typedef pair<ll, ll> pi; #define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i) #define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i) #define nl "\n" #define sp " " #define all(x) (x).begin(), (x).end() #define sc second #define fr first #define pb emplace_back void print(vi &temp) { for (auto x : temp) cout << x << ' '; cout << nl; } void solve() { int n; cin >> n; vi a(n+1), b(n); for (auto &x : a) cin >> x; for (auto &x : b) cin >> x; sort(a.begin(), a.end()); sort(b.begin(), b.end()); // print(b); vi ans(n + 1); vi pref(n + 1); // [start, i) vi suff(n + 1); // [i, end] pref[0] = 0; suff[n] = 0; for (int i = 1; i <= n; ++i) { pref[i] = max(pref[i - 1], max(a[i - 1] - b[i - 1], 0LL)); } for (int i = n - 1; i >= 0; --i) { suff[i] = max(suff[i + 1], max(a[i + 1] - b[i], 0LL)); } ans[0] = suff[0]; ans[n] = pref[n]; for (int i = 1; i < n; ++i) { ans[i] = max(suff[i], pref[i]); } print(ans); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...