Submission #384279

# Submission time Handle Problem Language Result Execution time Memory
384279 2021-04-01T07:32:38 Z sumit_kk10 Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
121 ms 13332 KB
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;

void solve(){
	int n;
	cin >> n;
	pair<int, int> a[n + 1], b[n];
	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].first;
		b[i].second = i;
	}
	sort(a, a + n + 1);
	sort(b, b + n);
	// now for each i in a it is removed then we take a[i] - b[i]. :hmm:
	int ans[n + 1][2];
	for(int i = 0; i < n; ++i){
		ans[i][0] = max(a[i].first - b[i].first, 0);
		ans[i][1] = max(a[i + 1].first - b[i].first, 0);
	}
	ans[n][1] = 0;
	ans[n][0] = 0;
	int pre_mx[n + 1] = {0}, suf_mx[n + 1] = {0};
	pre_mx[0] = ans[0][0];
	for(int i = 1; i <= n; ++i)
		pre_mx[i] = max(pre_mx[i - 1], ans[i][0]);
	suf_mx[n] = 0;
	suf_mx[n - 1] = ans[n - 1][1];
	for(int i = n - 2; i >= 0; --i)
		suf_mx[i] = max(suf_mx[i + 1], ans[i][1]);
	vector<int> res(n + 1);
	for(int i = 0; i <= n; ++i){
		int idx = a[i].second;
		if(i != 0)
			res[idx] = max(pre_mx[i - 1], suf_mx[i]);
		else
			res[idx] = suf_mx[i];
		// cout << ans[i][1] << ' ';
	}
	// cout << endl;
	for(auto k : res)
		cout << k << ' ';
	cout << "\n";
}

int main(){
    fast;
	int t = 1;
	// cin >> t;
	while(t--)
		solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 2 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 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 2 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 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 3 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 2 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 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 492 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 3 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 104 ms 12268 KB Output is correct
34 Correct 108 ms 12820 KB Output is correct
35 Correct 106 ms 12456 KB Output is correct
36 Correct 110 ms 12780 KB Output is correct
37 Correct 110 ms 13332 KB Output is correct
38 Correct 114 ms 13036 KB Output is correct
39 Correct 105 ms 12268 KB Output is correct
40 Correct 105 ms 12012 KB Output is correct
41 Correct 108 ms 12140 KB Output is correct
42 Correct 104 ms 12140 KB Output is correct
43 Correct 104 ms 12012 KB Output is correct
44 Correct 115 ms 11756 KB Output is correct
45 Correct 108 ms 11756 KB Output is correct
46 Correct 121 ms 11628 KB Output is correct
47 Correct 112 ms 11884 KB Output is correct
48 Correct 109 ms 11884 KB Output is correct
49 Correct 119 ms 12524 KB Output is correct
50 Correct 109 ms 12396 KB Output is correct
51 Correct 108 ms 12396 KB Output is correct
52 Correct 108 ms 12524 KB Output is correct
53 Correct 110 ms 12652 KB Output is correct