• CodeForces 34B Sale


    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/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("
    ");
    20                 for(j=1;j<=n;j++)
    21                     if(j%2==0)
    22                         printf("C");
    23                     else
    24                         printf(".");
    25                 printf("
    ");
    26             }
    27         }
    28         else
    29         {
    30             printf("%d
    ",(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("
    ");
    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("
    ");
    50                 }
    51             }
    52         }
    53     }
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    Alpha冲刺Day5
    Alpha冲刺Day4
    Alpha冲刺Day3
    团队作业——随堂小测
    Alpha冲刺Day2
    Alpha冲刺Day1
    团队项目需求分析
    结对项目第二次作业
    Linux中exec命令相关
    .lib和.dll文件
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771526.html
Copyright © 2020-2023  润新知