Skip to content

Commit 0b40abb

Browse files
authored
greedy
1 parent e3bf270 commit 0b40abb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: SWEA/3503.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//greedy
2+
3+
#include <stdio.h>
4+
#include <algorithm>
5+
using namespace std;
6+
int h[10001], nh[10001];
7+
int main(){
8+
int i;
9+
int tc, T;
10+
int N;
11+
for (scanf("%d", &T), tc = 1; tc <= T; ++tc){
12+
for (scanf("%d", &N), i = 1; i <= N; i++) scanf("%d",h+i);
13+
sort(h + 1, h + 1 + N);
14+
int l = 1;
15+
int r = N;
16+
int t = 0;
17+
for (i = 1; i <= N; i++){
18+
if (i & 1) nh[l++] = h[i];
19+
else nh[r--] = h[i];
20+
}
21+
int ans = nh[N] - nh[1];
22+
for (i = 2; i <= N; i++){
23+
int d = nh[i] - nh[i - 1];
24+
if (d < 0) d = -d;
25+
if (ans < d) ans = d;
26+
}
27+
printf("#%d %d\n",tc,ans);
28+
}
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)