답안 #365249

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365249 2021-02-11T10:14:58 Z Meloric Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
122 ms 15720 KB
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()

using namespace std;

const int inf  = 1e18;

void p(vector<int>& A){
	//for(auto e : A)cout << e << ' ';
	//cout << '\n';
}
void solve(){
	int n; cin >> n;
	vector<pii>A(n+1);
	vector<int>B(n);
	for(int i = 0; i< n+1; i++)cin >> A[i].X, A[i].Y = i;
	for(int i = 0; i< n; i++)cin >> B[i];
	
	sort(all(A));
	sort(all(B));
	
	vector<int> pref(n), suff(n);
	for(int i = 0; i< n; i++)pref[i] = max(A[i].X-B[i], 0l);
	for(int i = 0; i< n; i++)suff[i] = max(A[i+1].X-B[i], 0l);
	p(pref);p(suff);
	
	for(int i = 1; i< n; i++)pref[i] = max(pref[i], pref[i-1]);
	for(int i = n-2; i>=0; i--)suff[i] = max(suff[i], suff[i+1]);
	
	p(pref);p(suff);
	
	vector<int> ans(n+1);
	ans[A[0].Y] = suff[0];
	ans[A[n].Y] = pref[n-1];
	
	for(int i = 1; i< n; i++){
		ans[A[i].Y] = max(pref[i-1], suff[i]);
		//cout << A[i].Y << ' ';
	}
	//cout << '\n';
	for(auto e : ans)cout << e << ' ';
}

	
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t = 1;
	//cin >> t;
	while(t--)solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 512 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 102 ms 14444 KB Output is correct
34 Correct 108 ms 15104 KB Output is correct
35 Correct 114 ms 14700 KB Output is correct
36 Correct 106 ms 15084 KB Output is correct
37 Correct 111 ms 15720 KB Output is correct
38 Correct 108 ms 15340 KB Output is correct
39 Correct 108 ms 14444 KB Output is correct
40 Correct 118 ms 14316 KB Output is correct
41 Correct 108 ms 14444 KB Output is correct
42 Correct 107 ms 14444 KB Output is correct
43 Correct 111 ms 14316 KB Output is correct
44 Correct 109 ms 13804 KB Output is correct
45 Correct 114 ms 13932 KB Output is correct
46 Correct 105 ms 13844 KB Output is correct
47 Correct 117 ms 14316 KB Output is correct
48 Correct 114 ms 14188 KB Output is correct
49 Correct 122 ms 14844 KB Output is correct
50 Correct 108 ms 14828 KB Output is correct
51 Correct 112 ms 14868 KB Output is correct
52 Correct 111 ms 14828 KB Output is correct
53 Correct 108 ms 14788 KB Output is correct