답안 #959794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959794 2024-04-09T06:06:38 Z happy_node Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
88 ms 12492 KB
#include <bits/stdc++.h>
using namespace std;

const int MX=2e5+5;

int N;
int A[MX], B[MX], pf[MX], sf[MX], ans[MX], rev[MX];

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

	cin>>N;
	for(int i=1;i<=N+1;i++) cin>>A[i];
	for(int i=1;i<=N;i++) cin>>B[i];
	vector<int> ordA,ordB;
	for(int i=1;i<=N+1;i++) ordA.push_back(i);
	for(int i=1;i<=N;i++) ordB.push_back(i);
	sort(ordA.begin(),ordA.end(),[&](int i, int j){
		return A[i]<A[j];
	});
	sort(ordB.begin(),ordB.end(),[&](int i, int j){
		return B[i]<B[j];
	});

	for(int i=1;i<=N;i++) {
		int x=ordA[i-1],y=ordB[i-1];
		pf[i]=max(pf[i-1],max(0,A[x]-B[y]));
	}
	for(int i=N+1;i>1;i--) {
		int x=ordA[i-1],y=ordB[i-2];
		sf[i]=max(sf[i+1],max(0,A[x]-B[y]));
	}

	for(int i=1;i<=N+1;i++) {
		ans[i]=max(pf[i-1],sf[i+1]);
	}
	int p=1;
	for(auto x:ordA) {
		rev[x]=p;
		p++;
	}
	for(int i=1;i<=N+1;i++) {
		cout<<ans[rev[i]]<<" ";
	}
	cout<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2440 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2440 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2404 KB Output is correct
15 Correct 2 ms 2528 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 3 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 2 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 1 ms 2440 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2404 KB Output is correct
15 Correct 2 ms 2528 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 3 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 2 ms 2392 KB Output is correct
33 Correct 79 ms 11772 KB Output is correct
34 Correct 81 ms 12020 KB Output is correct
35 Correct 80 ms 11988 KB Output is correct
36 Correct 80 ms 12368 KB Output is correct
37 Correct 80 ms 12492 KB Output is correct
38 Correct 81 ms 12368 KB Output is correct
39 Correct 88 ms 11568 KB Output is correct
40 Correct 79 ms 11600 KB Output is correct
41 Correct 78 ms 11604 KB Output is correct
42 Correct 79 ms 11668 KB Output is correct
43 Correct 78 ms 11612 KB Output is correct
44 Correct 77 ms 11256 KB Output is correct
45 Correct 78 ms 11324 KB Output is correct
46 Correct 82 ms 11340 KB Output is correct
47 Correct 68 ms 11084 KB Output is correct
48 Correct 60 ms 11084 KB Output is correct
49 Correct 81 ms 11704 KB Output is correct
50 Correct 81 ms 11860 KB Output is correct
51 Correct 79 ms 11728 KB Output is correct
52 Correct 79 ms 11724 KB Output is correct
53 Correct 80 ms 11916 KB Output is correct