Submission #202877

#TimeUsernameProblemLanguageResultExecution timeMemory
202877EntityITJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
134 ms7032 KiB
#include<bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define sz(x) ( (int)(x).size() ) using LL = long long; template<class T> inline bool asMn(T &a, const T &b) { return a > b ? a = b, true : false; } template<class T> inline bool asMx(T &a, const T &b) { return a < b ? a = b, true : false; } mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() ); int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef FourLeafClover freopen("input", "r", stdin); #endif // FourLeafCLover int n; cin >> n; vector<pair<int, int> > a(n + 1); for (int i = 0; i < sz(a); ++i) { cin >> a[i].first; a[i].second = i; } sort(all(a) ); vector<int> b(n); for (int i = 0; i < sz(b); ++i) cin >> b[i]; sort(all(b) ); vector<int> ans(n + 1); vector<int> pref(n); for (int i = 0; i < sz(pref); ++i) { if (i) pref[i] = pref[i - 1]; asMx(pref[i], max(0, a[i].first - b[i]) ); } vector<int> suff(n); for (int i = n - 1; ~i; --i) { if (i + 1 < sz(suff) ) suff[i] = suff[i + 1]; asMx(suff[i], max(0, a[i + 1].first - b[i]) ); } for (int i = 0; i <= n; ++i) { if (i) asMx(ans[ a[i].second ], pref[i - 1]); if (i < n) asMx(ans[ a[i].second ], suff[i]); } for (auto i : ans) cout << i << ' '; cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...