제출 #203211

#제출 시각아이디문제언어결과실행 시간메모리
203211staniewzkiJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
313 ms14844 KiB
#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector<PII> a(n + 1);
	REP(i, n + 1) {
		cin >> a[i].ST;
		a[i].ND = i;
	}

	vector<int> b(n);
	REP(i, n) cin >> b[i];
	
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	multiset<int> s;
	REP(i, n) {
		int f = max(a[i].ST - b[i], 0);
		s.emplace(f);
	}

	vector<int> ans(n + 1);
	ans[a[n].ND] = *s.rbegin();

	for(int i = n - 1; i >= 0; i--) {
		int f = max(a[i].ST - b[i], 0);
		s.erase(s.find(f));
		f = max(a[i + 1].ST - b[i], 0);
		s.emplace(f);
		ans[a[i].ND] = *s.rbegin();
	}

	REP(i, n + 1) cout << ans[i] << " ";
	cout << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...