Submission #371275

# Submission time Handle Problem Language Result Execution time Memory
371275 2021-02-26T10:37:39 Z sam571128 Just Long Neckties (JOI20_ho_t1) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 2e5+5;
int pref[N], suff[N];

signed main(){
	fastio
	int n;
	cin >> n;
	vector<pair<int,int>> v;
	int ans[n+1] = {};
	for(int i = 0;i < n+1;i++){
		int tmp;
		cin >> tmp;
		v.push_back({tmp,i});
	}
	sort(v.begin(),v.end());
	int arr[n];
	for(auto &x : arr) cin >> x;
	sort(arr,arr+n);
	for(int i = 0;i < n;i++){
		pref[i] = abs(v[i].first-arr[i]);
		if(i!=0) pref[i] = max(pref[i],pref[i-1]);  
	}
	for(int i = n-1;~i;i--){
		suff[i] = abs(v[i+1].first-arr[i]);
		if(i!=n-1) suff[i] = max(suff[i],suff[i+1]);
	}
	for(int i = 0;i <= n;i++){
		ans[v[i].second] = max((i==0 ? (int)0 : pref[i-1]),suff[i]);
	}
	for(auto x : ans) cout << x << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -