SaleTime
limit:2000MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i6 4u SubmitStatusPracticecodeforces 34B
Description
Once Bob got to a sale of the old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets has a negative price-their owners is 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 have no desire to go to the sale for the Seco nd time. Please, help Bob find out the maximum sum of money that he can earn.
Input
The first line contains the space-separated integers n and m (1≤ m ≤ n ≤ -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≤a i ≤1000)-prices of the TV sets.
Output
Output the only number-the maximum sum of money this 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 }
Codeforces 34B Sale