1 /*LK's problem
 2 时间限制:3000 ms  |  内存限制:65535 KB 
 3 难度:1
 4 描述 
 5 LK has a question.Coule you help her?
 6 It is the beginning of the day at a bank, and a crowd  of clients is already waiting for the entrance door to  open. 
 7 Once the bank opens, no more clients arrive, and  tellerCount tellers begin serving the clients. A  
 8 teller takes serviceTime minutes to serve each client.  clientArrivals specifies how long each client has  already been waiting at the moment when the
 9  bank door  opens. Your program should determine the best way to arrange the clients into tellerCount queues, so that  the waiting time of the client
10   who waits longest is minimized. The waiting time of a client is the sum of  the time the client waited outside before the bank opened, the time the 
11   client waited in a queue once the  bank opened until the service began, and the service time of the client. Return the minimum waiting time for the 
12   client who waits the longest.
13 输入
14 The input will consist of several test cases. For each test case, one integer N (1<= N <= 100) is given in the first line. Second line contains N 
15 integers telling us the time each client had waited.Third line contains tow integers , teller's count and service time per client need. The input is 
16 terminated by a single line with N = 0.
17 输出
18 For each test of the input, print the answer.
19 样例输入
20 2
21 1 2
22 1 10
23 1
24 10 
25 50 50
26 0样例输出
27 21
28 60来源
29 TOPCODER
30 上传者
31 iphxer
32 */
33 #include<stdio.h>
34 int main()
35 {
36      int n;
37      while(scanf("%d", &n) != EOF && n)
38      {
39             int s[110], count, time, i, min, t, j, c[110];
40             for(i = 0; i < n; i++)
41             scanf("%d", &s[i]);
42             scanf("%d%d", &count, &time);
43             for(i = 0; i< n; i++)
44             for(j = i+1; j< n ; j++)
45             if(s[i] < s[j])
46             {
47                 t = s[i];
48                 s[i] = s[j];
49                 s[j] = t;
50             } 
51             for(i = 0 , j = 0; i < n; i = i + count, j++)
52             c[j] = s[i] + time*(j+1);
53             min  = c[0];
54             for(i= 1 ; i< j; i++)
55             if( min < c[i])
56                 min = c[i];
57             printf("%d\n", min);
58             /*
59             if(n % count == 0)
60              n /= count;
61             else
62             {
63                 n /= count;
64                 n++;
65             }
66             printf("%d\n", n*time + min);*/
67      }
68      return 0;
69 }