Submission #506157

# Submission time Handle Problem Language Result Execution time Memory
506157 2022-01-11T18:10:47 Z thomas_li Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
258 ms 23240 KB
#include <bits/stdc++.h>
using namespace std;
const int MM = 2e5+5;
int n; long long pref[MM],suff[MM],c[MM],a[MM],b[MM],org[MM];
map<int,int> pos;
int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n+1; i++){
		cin >> a[i];
		org[i] = a[i];
	}
	for(int i = 1; i <= n; i++){
		cin >> b[i];
	}
	sort(b+1,b+1+n); sort(a+1,a+2+n);
	for(int i = 1; i <= n+1; i++){
		pos[a[i]] = i;
	}
	pref[0] = -1e18;
	for(int i = 1; i <= n; i++){
		pref[i] = max(pref[i-1],max(0ll,a[i]-b[i]));
	}
	suff[n+2] = -1e18;
	for(int i = n+1; i >= 2; i--){
		suff[i] = max(suff[i+1],max(0ll,a[i]-b[n-(n+1-i)]));
	}
	for(int i = 1; i <= n+1; i++){
		int p = pos[org[i]];	
		cout << max(pref[p-1],suff[p+1]) << " \n"[i==n+1];
	}

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 460 KB Output is correct
33 Correct 232 ms 21852 KB Output is correct
34 Correct 217 ms 22724 KB Output is correct
35 Correct 202 ms 21956 KB Output is correct
36 Correct 201 ms 22572 KB Output is correct
37 Correct 230 ms 23240 KB Output is correct
38 Correct 241 ms 22980 KB Output is correct
39 Correct 211 ms 21976 KB Output is correct
40 Correct 207 ms 21784 KB Output is correct
41 Correct 215 ms 22128 KB Output is correct
42 Correct 240 ms 22000 KB Output is correct
43 Correct 258 ms 21836 KB Output is correct
44 Correct 202 ms 21212 KB Output is correct
45 Correct 199 ms 21368 KB Output is correct
46 Correct 213 ms 21316 KB Output is correct
47 Correct 111 ms 14356 KB Output is correct
48 Correct 114 ms 14372 KB Output is correct
49 Correct 222 ms 22520 KB Output is correct
50 Correct 211 ms 22464 KB Output is correct
51 Correct 250 ms 22608 KB Output is correct
52 Correct 215 ms 22568 KB Output is correct
53 Correct 241 ms 22516 KB Output is correct