제출 #1278999

#제출 시각아이디문제언어결과실행 시간메모리
1278999IBoryJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
201 ms16272 KiB
#include <bits/stdc++.h>
#define pii pair<int, int>
typedef long long ll;
using namespace std;

const int MAX = 200007;
ll B[MAX], ans[MAX];
pii A[MAX];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N;
	cin >> N;
	for (int i = 0; i <= N; ++i) {
		cin >> A[i].first;
		A[i].second = i;
	}
	for (int i = 0; i < N; ++i) cin >> B[i];
	sort(A, A + N + 1);
	sort(B, B + N);
	ll cur = 0;
	multiset<int> odd;
	for (int i = 0; i < N; ++i) odd.insert(max(0LL, A[i + 1].first - B[i]));
	ans[A[0].second] = *prev(odd.end());
	for (int i = 1; i <= N; ++i) {
		odd.erase(odd.find(max(0LL, A[i].first - B[i - 1])));
		odd.insert(max(0LL, A[i - 1].first - B[i - 1]));
		ans[A[i].second] = *prev(odd.end());
	}
	for (int i = 0; i <= N; ++i) cout << ans[i] << ' ';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...