제출 #1114931

#제출 시각아이디문제언어결과실행 시간메모리
1114931AdamGSJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
83 ms17100 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	vector<ll> ludzie;
	vector<pair<ll, int>> szef;
	
	ll p1;
	
	int n;
	
	cin >> n;
	
	for (int i = 0; n >= i; i++) {
		cin >> p1;
		szef.push_back({p1, i});
	}
	for (int i = 0; n > i; i++) {
		cin >> p1;
		ludzie.push_back(p1);
	}
	sort(ludzie.begin(), ludzie.end());
	sort(szef.begin(), szef.end());
	
	vector<ll> pref(n+2);
	vector<ll> suf(n + 2);
	vector<ll> wynik(n+2);
	
	pref[0] = (ll)0;
	suf[n + 1] = (ll)0;
	for (int i = 1; n >= i; i++) {
		pref[i] = max(pref[i - 1], szef[i - 1].first - ludzie[i - 1]);
		//cout << i << " " << pref[i] << "\n";
	}
	for (int i = n; i > 0; i--) {
		suf[i] = max(suf[i + 1], szef[i].first - ludzie[i - 1]);
		//cout << i << " " << suf[i] << "\n";
	}
	for (int i = 1; n + 1 >= i; i++) {
		wynik[szef[i - 1].second] = max(pref[i - 1], suf[i]);
	}
	for (int i = 0; n >= i; i++) {
		cout << wynik[i] << " " ;
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...