编程大赛-2



Problem 4: man

 



Management (man)


There are n boxes sequentially arranged in a row, 0 < n < 200000.  Our management has put some money into each box. You have been given a great opportunity to be rich. You can empty as many boxes as you like but have to obey a rule. The rule says you may not take money from any three consecutive boxes. Your task is to calculate how rich you can be.

 

Input

+Line 1 of standard input contains a single integer  -  the number of boxes.

+Line i + 1, (where 1 <= <= n) of standard input contains one positive integer less than 30000. It tells how much money is in i-th box.

 

Output

The standard output contains a single integer totalling the maximum amount of money you can have.

 

Example.

For sample input:

 

7

2

3

6

8

11

9

7

 

a correct output format:

32

 

________________________________

(Hint. 2 + 6 + 8 + 9 + 7 = 32)

 


Problem 5: gam



GAM


 

You play the following game against your opponent. There is a starting number n and a set S of a few numbers. In the first move you must subtract a number belonging to S fromn.  After your turn, the opponent decreases your result by a number from S, and then it is your turn and so on. When a player subtracts a number and the result is 0 or a negative number, then he/she looses the game. Your opponent plays optimally, that is, once given a chance, he/she will win and you will lose.

 

Input: (standard input)

+Line 1 contains two space-separated integers:

n, where 1 <= n <= 10000,

k, where 1 <= k <= 2000 (this is a number of elements of S).

+Line 2 contains k space-separated positive integers  (these are elements of S).

 

Output: (standard output)

Your program should write a number you need to subtract at the very beginning of the game in order to win or 0 if there is no such a number. If there are many possibilities to win the game, write the largest possible number.

 

Example:

For sample input:

11 3

2 4 3

a correct output format:

4

 

 


Problem 6: bas



BAS


 

There are n baskets numbered from 1 to n. Each basket has some money in it. The total of the money is less than 232. You have to “evenly” distribute the money between k people waiting. You are allowed to give each person only consecutively numbered baskets. (Some of them possibly get nothing). Some persons may get more than the other. Try to keep the maximum sum of money a person can get as low as possible.

 

Input: (standard input)

+Line 1 contains two space-separated integers:  n and k, where 1 <= n <= 100000, this is a number of baskets, and 1 <= k <= 50000 this is a number of people waiting.

+Line 2 contains n space-separated integers: which is the amount of money in each basket.

 

Output: (standard output)

Your program should write the smallest sum of money the richest person can get.

 

Example:

For sample input:

5 3

1 3 7 5 3

a correct output format:

8

 

 

________________________________________________________________________

(Hint: You should distribute the money as follows:  [1, 3], [7], [5, 3])

posted @ 2015-09-24 14:47  forwardslash  阅读(69)  评论(0)    收藏  举报