码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 34B Sale

时间:2015-08-30 21:11:59      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

Sale
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he‘s very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.

Input

The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets.

Output

Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.

Sample Input

Input
5 3
-6 0 35 -2 4
Output
8
Input
4 2
7 0 0 -7
Output
7
技术分享
 1 #include <stdio.h>
 2 #include <string.h>
 3 int main()
 4 {
 5     int n;
 6     int i,j,k;
 7     while(scanf("%d",&n)!=EOF)
 8     {
 9         if(n%2==0)
10         {
11             printf("%d\n",n*n/2);
12             for(i=1;i<=n/2;i++)
13             {
14                 for(j=1;j<=n;j++)
15                     if(j%2==1)
16                         printf("C");
17                     else
18                         printf(".");
19                 printf("\n");
20                 for(j=1;j<=n;j++)
21                     if(j%2==0)
22                         printf("C");
23                     else
24                         printf(".");
25                 printf("\n");
26             }
27         }
28         else
29         {
30             printf("%d\n",(n+1)*(n+1)/4+(n-1)*(n-1)/4);
31             for(i=1;i<=n;i++)
32             {
33                 if(i%2==1)
34                 {
35                     for(j=1;j<=n;j++)
36                         if(j%2==1)
37                             printf("C");
38                         else
39                             printf(".");
40                     printf("\n");
41                 }
42                 else
43                 {
44                     for(j=1;j<=n;j++)
45                         if(j%2==0)
46                             printf("C");
47                         else
48                             printf(".");
49                     printf("\n");
50                 }
51             }
52         }
53     }
54     return 0;
55 }
View Code

 

CodeForces 34B Sale

标签:

原文地址:http://www.cnblogs.com/cyd308/p/4771526.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!