Submission #1181065

#TimeUsernameProblemLanguageResultExecution timeMemory
1181065miniobJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
130 ms7888 KiB
#include <bits/stdc++.h>
using namespace std;

int maxpref[200007];
int maxsuf[200007];
int wyn[200007];

int main() 
{
	int n;
	vector<pair<int, int>> war;
	vector<int> war2;
	cin >> n;
	for(int i = 1; i <= n + 1; i++)
	{
		int x;
		cin >> x;
		war.push_back({x, i});
	}
	for(int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		war2.push_back(x);
	}
	sort(war.begin(), war.end());
	sort(war2.begin(), war2.end());
	for(int i = 1; i <= n; i++)
	{
		maxpref[i] = max(maxpref[i - 1], war[i - 1].first - war2[i - 1]);
	}
	for(int i = n; i > 0; i--)
	{
		maxsuf[i] = max(maxsuf[i + 1], war[i].first - war2[i - 1]);
	}
	for(int i = 1; i <= n + 1; i++)
	{
		wyn[war[i - 1].second] = max(maxpref[i - 1], maxsuf[i]);
	}
	for(int i = 1; i <= n + 1; i++)
	{
		cout << wyn[i] << " ";
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...