请教各位大神怎样跳跃输出数组元素,渣渣伤不起啊求大神解答

请问各位大神怎样跳跃输出数组元素,渣渣伤不起啊。求大神解答。
1002. Bouncing Sequence
Total: 87 Accepted: 70
     
Time Limit: 1sec    Memory Limit:256MB
Description
Given a sequence a with size n(1 ≤ n ≤ 4,000), a bouncing sequence b of a is constructed in the following way. b0 is the smallest element of sequence a, b1 is the largest element of a excluding b0, b2 is the smallest element of a excluding {b0, b1}, and so on. Given a sequence a, please output corresponding bouncing sequence b.

Input
The first line contains one integer n(1 ≤ n ≤ 4,000) -  the length of the sequence.

The second line contains n integers a0, a1, ..., an-1(0 < ai < 231) .

Output
Print a's the bouncing sequence b. Print each element a line.

Sample Input
 Copy sample input to clipboard
5
1 6 3 9 2
Sample Output
1
9
2
6
3
Hint
In the sample,

b[0] is the smallest element of [1, 6, 3, 9, 2], so b[0] is 1.
b[1] is the largest element of [6, 3, 9, 2], so b[1] is 9.
b[2] is the smallest element of [6, 3, 2], so b[2] is 2.
b[3] is the largest element of [6, 3], so b[3] is 6.
b[4] is the smallest element of [3], so b[4] is 3.

so b is [1, 9, 2, 6, 3]

Problem Source: J. Li

     
Submit
------解决思路----------------------
#include <stdio.h>
int d[4000];
static int m[4000];
int i,j,k,n,mind,maxd;
int main() {
    scanf("%d",&n);
    if (!(1<=n && n<=4000)) return 1;
    for (i=0;i<n;i++) {
        scanf("%d",&d[i]);
        if (!(0<d[i] && d[i]<231)) return 2;
    }
    for (j=0;j<n;j++) {
        if (j%2==0) {
            mind=231;
            for (i=0;i<n;i++) {
                if (m[i]==0) {
                    if (d[i]<=mind) {
                        k=i;
                        mind=d[i];
                    }
                }
            }
            printf("%d\n",mind);
            m[k]=1;
        } else {
            maxd=0;
            for (i=0;i<n;i++) {
                if (m[i]==0) {
                    if (d[i]>=maxd) {
                        k=i;
                        maxd=d[i];
                    }
                }
            }
            printf("%d\n",maxd);
            m[k]=1;
        }
    }
    return 0;
}