Submission #1287865

#TimeUsernameProblemLanguageResultExecution timeMemory
1287865MinhKienJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
178 ms14712 KiB
#include <algorithm> #include <iostream> #include <set> using namespace std; #define ii pair <int, int> #define fi first #define se second const int N = 2e5 + 10; class CMP { public: bool operator () (const int &x, const int &y) const { return x > y; } }; int n, x[N], ans[N]; ii a[N]; multiset <int, CMP> ms; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n + 1; ++i) { cin >> a[i].fi; a[i].se = i; } sort(a + 1, a + n + 2); for (int i = 1; i <= n; ++i) cin >> x[i]; sort(x + 1, x + n + 1); for (int i = 1; i <= n; ++i) { ms.insert(max(0, a[i].fi - x[i])); } for (int i = n + 1; i >= 1; --i) { ans[a[i].se] = *ms.begin(); if (i > 1) { ms.erase(max(0, a[i - 1].fi - x[i - 1])); ms.insert(max(0, a[i].fi - x[i - 1])); } } for (int i = 1; i <= n + 1; ++i) { cout << ans[i] << " "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...