Submission #702463

# Submission time Handle Problem Language Result Execution time Memory
702463 2023-02-24T06:31:50 Z Koful123 Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
95 ms 15504 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
 
void solve(){

	int n;
	cin >> n;

	vector<pair<int,int>> a(n + 1);
	for(int i = 0; i < n + 1; i++){
		cin >> a[i].ff; a[i].ss = i;
	}

	vector<int> b(n);
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}

	sort(all(a)); sort(all(b));
	vector<int> one(n + 1),two(n + 2);
	for(int i = 0; i < n; i++){
		one[i] = max((i > 0 ? one[i - 1] : 0),a[i].ff - b[i]);
	}
	for(int i = n; i >= 1; i--){
		two[i] = max(two[i + 1],a[i].ff - b[i - 1]);
	}

	vector<int> res(n + 1);
	for(int i = 0; i < n + 1; i++){
		res[a[i].ss] = max((i + 1 < n + 1 ? two[i + 1] : 0),(i > 0 ? one[i - 1] : 0));
	}

	for(int x : res){
		cout << x << ' ';
	}
}
 
signed main(){ 
 
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int t = 1;
//	cin >> t;
 
	while(t--)
		solve();
 	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 85 ms 14416 KB Output is correct
34 Correct 90 ms 15024 KB Output is correct
35 Correct 84 ms 14532 KB Output is correct
36 Correct 86 ms 14948 KB Output is correct
37 Correct 93 ms 15504 KB Output is correct
38 Correct 85 ms 15292 KB Output is correct
39 Correct 83 ms 14284 KB Output is correct
40 Correct 81 ms 14220 KB Output is correct
41 Correct 83 ms 14500 KB Output is correct
42 Correct 85 ms 14376 KB Output is correct
43 Correct 80 ms 14284 KB Output is correct
44 Correct 84 ms 13784 KB Output is correct
45 Correct 83 ms 13876 KB Output is correct
46 Correct 78 ms 13768 KB Output is correct
47 Correct 79 ms 14064 KB Output is correct
48 Correct 95 ms 14164 KB Output is correct
49 Correct 87 ms 14704 KB Output is correct
50 Correct 85 ms 14640 KB Output is correct
51 Correct 89 ms 14824 KB Output is correct
52 Correct 87 ms 14796 KB Output is correct
53 Correct 83 ms 14672 KB Output is correct