笨蛋的难题(二)

Time Limit: 1000ms
Memory Limit: 128000KB
64-bit integer IO format:      Java class name:
笨蛋就业了,并且是在上千应聘中脱颖而出的,和他一起脱颖而出的还有傻子。公司的老板对二人视为珍宝,为了激励他们的工作热情,给他们一小时发一次工资(很高兴吧)。但每次只发给一个人,并且每次发的工资可能不同(老板很厉害吧)。傻子和笨蛋为了证明自己比对方智商高,他们事先知道每次发的工资的多少。他们暗中达成协议:他们不是将工资平分,而是轮流领取。该领工资的人可以选择跳过一个或多个小时的工资,而领取后面的工资。跳过的工资会捐给孤儿院。他们只管自己获得最大利益,不管对方获得的利益如何,每次笨蛋先领。比如 100, 100, 800, 70, 150 ,100。笨蛋第一个小时不领,第二个小时也不领,直接领第三个小时发的工资,傻子领第四个小时发的工资,笨蛋再领第五个小时发的工资,傻子再领第六个小时发的工资,这样笨蛋领到950元的工资,傻子领到170元的钱,其余的全部捐给孤儿院为200元。
 

Input

多组测试数据
第一行输入t,表示共发t个小时的工资(0<t<120)
接下来一行是t个数表示t小时内每个小时的工资Money(0<money<10000)
 

Output

三个数字M,N,V
他们分别表示笨蛋领的工资,傻子领的工资,还有捐给孤儿院的钱
 

Sample Input

6
100 100 800 70 150 100
3
100 100 100

Sample Output

950 170 200
200 100 0

 

到着想...

 

代码:

 1 #include <vector>
 2 #include <set>
 3 #include <algorithm>
 4 #include <iostream>
 5 #include <cstdio>
 6 #include <cmath>
 7 #include <cstdlib>
 8 #include <string>
 9 #include <cstring>
10 #include <queue>
11 #include <stack>
12 using namespace std;
13 #define N 1100
14 
15 int a[N];
16 
17 int main()
18 {
19     int t;
20     int m1,m2,p;
21     while(~scanf("%d",&t)){
22         int sum=0;
23         for(int i=0; i<t; i++){
24             scanf("%d",&a[i]);
25             sum+=a[i];
26         }
27         m1=m2=p=0;
28         for(int i=t-1; i>=0; i--){
29             if(a[i]+m2>=m1){
30                 p=m1;
31                 m1=a[i]+m2;
32                 m2=p;
33             }
34         }
35         printf("%d %d %d\n",m1,m2,sum-m1-m2);
36     }
37 }

 

posted @ 2016-05-11 16:41  Vmetrio  阅读(170)  评论(0编辑  收藏  举报