Submission #12136

# Submission time Handle Problem Language Result Execution time Memory
12136 2014-12-21T08:27:16 Z gs13105 격자 보존하기 (GA9_preserve) C++
100 / 100
36 ms 1868 KB
#include <stdio.h>
#include <algorithm>

int arr[100000];
int sor[100000];

inline bool cmp(const int &a,const int &b)
{
	return a>b;
}

inline int mn(int a,int b)
{
	return a<b?a:b;
}

inline int mx(int a,int b)
{
	return a>b?a:b;
}

int main()
{
	int n,k,d,r=0,i;
	scanf("%d%d%d",&n,&k,&d);
	for(i=0;i<k;i++)
		scanf("%d",&arr[i]);
	if(d==1)
	{
		printf("%d",mx(arr[0]-1,n-arr[k-1]));
		return 0;
	}
	if(k==1)
	{
		printf("%d",n-1);
		return 0;
	}
	if(d>=2*k)
	{
		printf("%d",n-k);
		return 0;
	}
	for(i=0;i<k-1;i++)
		sor[i]=arr[i+1]-arr[i]-1;
	std::sort(sor,sor+k-1,cmp);
	if(d%2)
	{
		for(i=0;i<(d-1)/2-1;i++)
			r+=sor[i];
		r+=mx(sor[(d-1)/2-1]+mx(arr[0]-1,n-arr[k-1]),arr[0]-1+n-arr[k-1]);
	}
	else
	{
		for(i=0;i<d/2-1;i++)
			r+=sor[i];
		r+=mx(arr[0]-1+n-arr[k-1],sor[d/2-1]);
	}
	printf("%d",r);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1868 KB Output is correct
2 Correct 0 ms 1868 KB Output is correct
3 Correct 0 ms 1868 KB Output is correct
4 Correct 0 ms 1868 KB Output is correct
5 Correct 0 ms 1868 KB Output is correct
6 Correct 0 ms 1868 KB Output is correct
7 Correct 0 ms 1868 KB Output is correct
8 Correct 0 ms 1868 KB Output is correct
9 Correct 0 ms 1868 KB Output is correct
10 Correct 0 ms 1868 KB Output is correct
11 Correct 0 ms 1868 KB Output is correct
12 Correct 0 ms 1868 KB Output is correct
13 Correct 0 ms 1868 KB Output is correct
14 Correct 0 ms 1868 KB Output is correct
15 Correct 0 ms 1868 KB Output is correct
16 Correct 0 ms 1868 KB Output is correct
17 Correct 0 ms 1868 KB Output is correct
18 Correct 0 ms 1868 KB Output is correct
19 Correct 0 ms 1868 KB Output is correct
20 Correct 0 ms 1868 KB Output is correct
21 Correct 0 ms 1868 KB Output is correct
22 Correct 0 ms 1868 KB Output is correct
23 Correct 0 ms 1868 KB Output is correct
24 Correct 0 ms 1868 KB Output is correct
25 Correct 0 ms 1868 KB Output is correct
26 Correct 0 ms 1868 KB Output is correct
27 Correct 0 ms 1868 KB Output is correct
28 Correct 0 ms 1868 KB Output is correct
29 Correct 0 ms 1868 KB Output is correct
30 Correct 0 ms 1868 KB Output is correct
31 Correct 0 ms 1868 KB Output is correct
32 Correct 0 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1868 KB Output is correct
2 Correct 0 ms 1868 KB Output is correct
3 Correct 0 ms 1868 KB Output is correct
4 Correct 0 ms 1868 KB Output is correct
5 Correct 0 ms 1868 KB Output is correct
6 Correct 0 ms 1868 KB Output is correct
7 Correct 0 ms 1868 KB Output is correct
8 Correct 0 ms 1868 KB Output is correct
9 Correct 0 ms 1868 KB Output is correct
10 Correct 0 ms 1868 KB Output is correct
11 Correct 0 ms 1868 KB Output is correct
12 Correct 0 ms 1868 KB Output is correct
13 Correct 0 ms 1868 KB Output is correct
14 Correct 0 ms 1868 KB Output is correct
15 Correct 0 ms 1868 KB Output is correct
16 Correct 0 ms 1868 KB Output is correct
17 Correct 0 ms 1868 KB Output is correct
18 Correct 0 ms 1868 KB Output is correct
19 Correct 0 ms 1868 KB Output is correct
20 Correct 0 ms 1868 KB Output is correct
21 Correct 0 ms 1868 KB Output is correct
22 Correct 0 ms 1868 KB Output is correct
23 Correct 0 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1868 KB Output is correct
2 Correct 0 ms 1868 KB Output is correct
3 Correct 0 ms 1868 KB Output is correct
4 Correct 0 ms 1868 KB Output is correct
5 Correct 0 ms 1868 KB Output is correct
6 Correct 0 ms 1868 KB Output is correct
7 Correct 0 ms 1868 KB Output is correct
8 Correct 0 ms 1868 KB Output is correct
9 Correct 0 ms 1868 KB Output is correct
10 Correct 0 ms 1868 KB Output is correct
11 Correct 0 ms 1868 KB Output is correct
12 Correct 0 ms 1868 KB Output is correct
13 Correct 0 ms 1868 KB Output is correct
14 Correct 0 ms 1868 KB Output is correct
15 Correct 0 ms 1868 KB Output is correct
16 Correct 0 ms 1868 KB Output is correct
17 Correct 0 ms 1868 KB Output is correct
18 Correct 0 ms 1868 KB Output is correct
19 Correct 0 ms 1868 KB Output is correct
20 Correct 0 ms 1868 KB Output is correct
21 Correct 0 ms 1868 KB Output is correct
22 Correct 0 ms 1868 KB Output is correct
23 Correct 0 ms 1868 KB Output is correct
24 Correct 0 ms 1868 KB Output is correct
25 Correct 0 ms 1868 KB Output is correct
26 Correct 0 ms 1868 KB Output is correct
27 Correct 0 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1868 KB Output is correct
2 Correct 24 ms 1868 KB Output is correct
3 Correct 32 ms 1868 KB Output is correct
4 Correct 32 ms 1868 KB Output is correct
5 Correct 32 ms 1868 KB Output is correct
6 Correct 32 ms 1868 KB Output is correct
7 Correct 32 ms 1868 KB Output is correct
8 Correct 20 ms 1868 KB Output is correct
9 Correct 8 ms 1868 KB Output is correct
10 Correct 8 ms 1868 KB Output is correct
11 Correct 24 ms 1868 KB Output is correct
12 Correct 28 ms 1868 KB Output is correct
13 Correct 32 ms 1868 KB Output is correct
14 Correct 32 ms 1868 KB Output is correct
15 Correct 32 ms 1868 KB Output is correct
16 Correct 32 ms 1868 KB Output is correct
17 Correct 24 ms 1868 KB Output is correct
18 Correct 20 ms 1868 KB Output is correct
19 Correct 28 ms 1868 KB Output is correct
20 Correct 0 ms 1868 KB Output is correct
21 Correct 0 ms 1868 KB Output is correct
22 Correct 32 ms 1868 KB Output is correct
23 Correct 28 ms 1868 KB Output is correct
24 Correct 32 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1868 KB Output is correct
2 Correct 16 ms 1868 KB Output is correct
3 Correct 32 ms 1868 KB Output is correct
4 Correct 36 ms 1868 KB Output is correct
5 Correct 20 ms 1868 KB Output is correct
6 Correct 32 ms 1868 KB Output is correct
7 Correct 28 ms 1868 KB Output is correct
8 Correct 20 ms 1868 KB Output is correct
9 Correct 8 ms 1868 KB Output is correct
10 Correct 4 ms 1868 KB Output is correct
11 Correct 20 ms 1868 KB Output is correct
12 Correct 16 ms 1868 KB Output is correct
13 Correct 24 ms 1868 KB Output is correct
14 Correct 8 ms 1868 KB Output is correct
15 Correct 16 ms 1868 KB Output is correct
16 Correct 20 ms 1868 KB Output is correct
17 Correct 16 ms 1868 KB Output is correct
18 Correct 12 ms 1868 KB Output is correct
19 Correct 20 ms 1868 KB Output is correct
20 Correct 20 ms 1868 KB Output is correct