Submission #365216

# Submission time Handle Problem Language Result Execution time Memory
365216 2021-02-11T09:07:02 Z jazzup Just Long Neckties (JOI20_ho_t1) C++17
100 / 100
181 ms 6276 KB
#include<cstdio>
#include<algorithm>

using namespace std;

int a[200010],aa[200010],b[200010],dp1[200010],dp2[200010];

int main(){

	int n;
	scanf("%d",&n);
	for(int i=0;i<=n;i++){
		scanf("%d",&aa[i]);
		a[i]=aa[i];
	}
	sort(a,a+n+1);
	for(int i=0;i<n;i++){
		scanf("%d",&b[i]);
	}
	sort(b,b+n);

	dp1[0]=max(a[0]-b[0],0);

	for(int i=1;i<n;i++){
		dp1[i]=max(dp1[i-1],max(a[i]-b[i],0));
	}

	dp2[n-1]=max(a[n]-b[n-1],0);

	for(int i=n-2;i>=0;i--){
		dp2[i]=max(dp2[i+1],max(a[i+1]-b[i],0));
	}

	for(int i=0;i<=n;i++){
		int *p=lower_bound(a,a+n+1,aa[i]);
		int x=p-a;
		printf("%d ",max(dp1[x-1],dp2[x]));
	}

	// for(int i=0;i<n;i++){
	// 	printf("%d ",dp1[i]);
	// }

	// printf("\n");
	// for(int i=0;i<n;i++){
	// 	printf("%d ",dp2[i]);
	// }
	return 0;
}

Compilation message

ho_t1.cpp: In function 'int main()':
ho_t1.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
ho_t1.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   scanf("%d",&aa[i]);
      |   ~~~~~^~~~~~~~~~~~~
ho_t1.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |   scanf("%d",&b[i]);
      |   ~~~~~^~~~~~~~~~~~
# 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 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 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 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 2 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 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 2 ms 364 KB Output is correct
31 Correct 2 ms 364 KB Output is correct
32 Correct 2 ms 364 KB Output is correct
33 Correct 150 ms 5612 KB Output is correct
34 Correct 173 ms 5868 KB Output is correct
35 Correct 153 ms 5656 KB Output is correct
36 Correct 156 ms 5996 KB Output is correct
37 Correct 161 ms 6276 KB Output is correct
38 Correct 166 ms 6252 KB Output is correct
39 Correct 160 ms 5228 KB Output is correct
40 Correct 166 ms 5228 KB Output is correct
41 Correct 152 ms 5384 KB Output is correct
42 Correct 151 ms 5356 KB Output is correct
43 Correct 152 ms 5228 KB Output is correct
44 Correct 173 ms 5064 KB Output is correct
45 Correct 177 ms 4972 KB Output is correct
46 Correct 152 ms 4972 KB Output is correct
47 Correct 113 ms 4716 KB Output is correct
48 Correct 122 ms 4792 KB Output is correct
49 Correct 166 ms 5484 KB Output is correct
50 Correct 160 ms 5356 KB Output is correct
51 Correct 163 ms 5484 KB Output is correct
52 Correct 181 ms 5512 KB Output is correct
53 Correct 161 ms 5356 KB Output is correct