Submission #231783

#TimeUsernameProblemLanguageResultExecution timeMemory
231783Haunted_CppJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
277 ms18680 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize ("Ofast") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") int main () { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<int, int> > a (n + 1); for (int i = 0; i <= n; i++) { cin >> a[i].first; a[i].second = i; } vector<int> pessoas (n); for (int i = 0; i < n; i++) cin >> pessoas[i]; sort (a.begin(), a.end()); sort (pessoas.begin(), pessoas.end()); multiset<int> diff; for (int i = 0; i < n; i++) { diff.insert( max (a[i].first - pessoas[i], 0) ); } vector<int> ans (n + 1, -1); ans[a[n].second] = *diff.rbegin(); int last = a[n].first; for (int i = n - 1; i >= 0; i--) { int current = max (a[i].first - pessoas[i], 0); diff.erase(diff.lower_bound(current)); diff.insert( max (last - pessoas[i], 0) ); ans[a[i].second] = *diff.rbegin(); last = a[i].first; } for (int i = 0; i <= n; i++) { if (i) cout << ' '; cout << ans[i]; } cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...