# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
995262 | gmroh06 | Just Long Neckties (JOI20_ho_t1) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
inline void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T> class arr {
private:
vector<T> v;
public:
arr(const ll& n) {
v.resize(n);
}
vector<T>::iterator begin() {
return v.begin();
}
vector<T>::iterator end() {
return v.end();
}
T& operator [] (const ll& idx) {
return v[idx];
}
friend ostream& operator << (ostream& out, const arr& x) {
for (auto &i : x.v) {
out << i << ' ';
}
return out;
}
friend istream& operator >> (istream& in, arr& x) {
for (auto &i : x.v) {
in >> i;
}
return in;
}
};
ll n;
int main() {
fastio();
cin >> n;
arr<ll> v(n), ans(n + 1);
arr<pll> p(n + 1);
for (ll i = 0, x; i <= n; i++) {
cin >> x;
p[i] = {x, i};
}
cin >> v;
sort(v.begin(), v.end());
sort(p.begin(), p.end());
multiset<ll> ms;
for (ll i = 0; i < n; i++) {
ms.insert(max(0LL, p[i + 1].first - v[i]));
}
for (ll i = 0; i <= n; i++) {
auto it = ms.end();
ans[p[i].second] = *(--it);
if (i != n) {
it = ms.lower_bound(max(0LL, p[i + 1].first - v[i]));
ms.erase(it);
ms.insert(max(0LL, p[i].first - v[i]));
}
}
cout << ans << '\n';
return 0;
}