zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    forms组件、cookie与session
    choices参数、MTV与MVC模型、Ajax、序列化组件、sweetalert搭建页面、自定义分页器
    Django 常用字段,数据库查询优化 only与defer
    django配置代码
    django 模板层、模型层
    Django 请求生命周期、路由层
    centos6.8安装httpd后无法访问
    初次认识dedecms和帝国cms内容管理系统
    遇到一个json解码失败的问题
    关于apache配置映射端口
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771526.html
Copyright © 2011-2022 走看看