We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e3bf270 commit 0b40abbCopy full SHA for 0b40abb
SWEA/3503.cpp
@@ -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