Submission #202926

# Submission time Handle Problem Language Result Execution time Memory
202926 2020-02-18T17:25:59 Z mraron Just Long Neckties (JOI20_ho_t1) C++14
100 / 100
180 ms 8568 KB
#include<bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
//3 4 6 7
//2 4 6
//3 4 7
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vector<pair<int,int>> a(n+1), b(n);
	for(int i=0;i<n+1;++i) {
		cin>>a[i].xx;
		a[i].yy=i;
	}
	for(int i=0;i<n;++i) {
		cin>>b[i].xx;
		b[i].yy=i;
	}
	
	//~ sort(b.begin(),b.end());	
	//~ for(int i=0;i<n+1;++i) {
		//~ vector<int> lst;
		//~ for(int j=0;j<n+1;++j) if(i!=j) lst.push_back(a[j].xx);
		//~ sort(lst.begin(),lst.end());
		//~ int mx=0;
		//~ for(int j=0;j<n;++j) mx=max(mx, max(0, lst[j]-b[j].xx));
		//~ cout<<mx<<" \n"[i==n];
	//~ }
	
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	vector<int> pre(n+1);
	vector<int> suf(n+1);
	for(int i=0;i<n;++i) {
		pre[i]=max(0, a[i+1].xx-b[i].xx);
		suf[i+1]=max(0, a[i].xx-b[i].xx);
	}
	
	for(int i=n-1;i>=0;i--) pre[i]=max(pre[i], pre[i+1]);
	for(int i=1;i<n+1;i++) suf[i]=max(suf[i], suf[i-1]);

	//~ for(auto i:pre) {
		//~ cerr<<i<<" ";
	//~ }cerr<<"\n";
	
	
	//~ for(auto i:suf) {
		//~ cerr<<i<<" ";
	//~ }cerr<<"\n";
	
	vector<int> ans=pre;
	for(int i=n;i>=0;i--) ans[i]=max(ans[i], suf[i]);
	vector<int> res(n+1);
	for(int i=0;i<n+1;++i) res[a[i].yy]=ans[i];
	for(int i=0;i<n+1;++i) cout<<res[i]<<" \n"[i==n];
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 5 ms 300 KB Output is correct
14 Correct 5 ms 380 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 6 ms 380 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 6 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 6 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 9 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 5 ms 300 KB Output is correct
14 Correct 5 ms 380 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 6 ms 380 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 6 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 6 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 6 ms 376 KB Output is correct
32 Correct 9 ms 376 KB Output is correct
33 Correct 132 ms 7964 KB Output is correct
34 Correct 130 ms 8132 KB Output is correct
35 Correct 116 ms 7928 KB Output is correct
36 Correct 128 ms 8416 KB Output is correct
37 Correct 125 ms 8568 KB Output is correct
38 Correct 127 ms 8440 KB Output is correct
39 Correct 120 ms 7544 KB Output is correct
40 Correct 128 ms 7544 KB Output is correct
41 Correct 125 ms 7692 KB Output is correct
42 Correct 123 ms 7672 KB Output is correct
43 Correct 129 ms 7544 KB Output is correct
44 Correct 125 ms 7288 KB Output is correct
45 Correct 121 ms 7288 KB Output is correct
46 Correct 119 ms 7212 KB Output is correct
47 Correct 129 ms 7192 KB Output is correct
48 Correct 126 ms 7160 KB Output is correct
49 Correct 121 ms 7780 KB Output is correct
50 Correct 180 ms 7800 KB Output is correct
51 Correct 126 ms 7800 KB Output is correct
52 Correct 124 ms 7748 KB Output is correct
53 Correct 143 ms 7776 KB Output is correct