답안 #216812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216812 2020-03-28T06:03:40 Z oolimry Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
119 ms 15608 KB
#include <bits/stdc++.h>

using namespace std;
typedef pair<long long, long long> ii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin >> n;
	ii A[n+1]; long long B[n];
	long long ans[n+1];
	for(int i = 0;i <= n;i++){
		cin >> A[i].first; A[i].second = i;
	}
	for(int i = 0;i < n;i++) cin >> B[i];
	
	sort(A, A + (n+1));
	sort(B, B + (n));
	
	long long pre[n];
	long long suf[n];
	
	for(int i = 0;i < n;i++){
		pre[i] = max(A[i].first - B[i], 0LL);
		if(i != 0) pre[i] = max(pre[i-1],pre[i]);
	}
	
	for(int i = 0;i < n;i++){
		suf[i] = max(A[n-i].first - B[n-i-1], 0LL);
		if(i != 0) suf[i] = max(suf[i-1],suf[i]);
	}
	
	for(int i = 0;i <= n;i++){
		long long res = 0;
		if(i != n) res = max(res, suf[n-i-1]);
		if(i != 0) res = max(res, pre[i-1]);
		ans[A[i].second] = res;
	}
	
	for(int i = 0;i <= n;i++) cout << ans[i] << " ";
	
}

/*
3
4 3 7 6
2 6 4
*/


# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 6 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 6 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 116 ms 14484 KB Output is correct
34 Correct 115 ms 15072 KB Output is correct
35 Correct 112 ms 14584 KB Output is correct
36 Correct 111 ms 15096 KB Output is correct
37 Correct 119 ms 15608 KB Output is correct
38 Correct 116 ms 15352 KB Output is correct
39 Correct 113 ms 14328 KB Output is correct
40 Correct 112 ms 14328 KB Output is correct
41 Correct 113 ms 14456 KB Output is correct
42 Correct 113 ms 14460 KB Output is correct
43 Correct 114 ms 14328 KB Output is correct
44 Correct 113 ms 13944 KB Output is correct
45 Correct 109 ms 14072 KB Output is correct
46 Correct 110 ms 13816 KB Output is correct
47 Correct 107 ms 14200 KB Output is correct
48 Correct 106 ms 14200 KB Output is correct
49 Correct 119 ms 14840 KB Output is correct
50 Correct 116 ms 14712 KB Output is correct
51 Correct 118 ms 14712 KB Output is correct
52 Correct 116 ms 14712 KB Output is correct
53 Correct 115 ms 14712 KB Output is correct