zoukankan      html  css  js  c++  java
  • cf 3B

    B. Lorry
    time limit per test
    2 seconds
    memory limit per test
    64 megabytes
    input
    standard input
    output
    standard output

    A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times bigger than kayaks (and occupy the space of 2 cubic metres).

    Each waterborne vehicle has a particular carrying capacity, and it should be noted that waterborne vehicles that look the same can have different carrying capacities. Knowing the truck body volume and the list of waterborne vehicles in the boat depot (for each one its type and carrying capacity are known), find out such set of vehicles that can be taken in the lorry, and that has the maximum total carrying capacity. The truck body volume of the lorry can be used effectively, that is to say you can always put into the lorry a waterborne vehicle that occupies the space not exceeding the free space left in the truck body.

    Input

    The first line contains a pair of integer numbers n and v (1 ≤ n ≤ 105; 1 ≤ v ≤ 109), where n is the number of waterborne vehicles in the boat depot, and v is the truck body volume of the lorry in cubic metres. The following n lines contain the information about the waterborne vehicles, that is a pair of numbers ti, pi (1 ≤ ti ≤ 2; 1 ≤ pi ≤ 104), where ti is the vehicle type (1 – a kayak, 2 – a catamaran), and pi is its carrying capacity. The waterborne vehicles are enumerated in order of their appearance in the input file.

    Output

    In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them.

    Sample test(s)
    input
    3 2
    1 2
    2 7
    1 3
    output
    7
    2
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<cstdlib>
    #include<algorithm>
    using namespace std;
    #define maxn 100010
    int n,v,sum1[maxn],sum2[maxn],ans[maxn],c1,c2;
    struct node
    {
          int val,id;
    }one[maxn],two[maxn];
    bool cmp(node a,node b)
    {
          return a.val>b.val;
    }
    int main()
    {
          int a,b,oc=0,tc=0,maxx=-1;
          scanf("%d%d",&n,&v);
          for(int i=1;i<=n;i++)
          {
              scanf("%d%d",&a,&b);
              if(a==1)
              {
                 one[++oc].val=b;
                 one[oc].id=i;
              }
              else if(a==2)
              {
                 two[++tc].val=b;
                 two[tc].id=i;
              }
          }
          sort(one+1,one+1+oc,cmp);
          sort(two+1,two+1+tc,cmp);
          for(int i=1;i<=oc;i++) sum1[i]=sum1[i-1]+one[i].val;
          for(int j=1;j<=tc;j++) sum2[j]=sum2[j-1]+two[j].val;
          for(int i=0;i<=oc;i++)
          {
                if(i>v)
                      break;
                int d=sum1[i]+sum2[min((v-i)/2,tc)];
                if(d>maxx)
                {
                      maxx=d;
                      c1=i;
                      c2=min((v-i)/2,tc);
                }
          }
          if(maxx==-1)
          {
                printf("0
    ");
                return 0;
          }
          printf("%d
    ",maxx);
          int cnt=0;
          for(int i=1;i<=c1;i++) ans[++cnt]=one[i].id;
          for(int i=1;i<=c2;i++) ans[++cnt]=two[i].id;
          for(int i=1;i<=cnt;i++)
                printf("%d%c",ans[i],i==cnt?'
    ':' ');
          return 0;
    
    }
    

      

  • 相关阅读:
    Python reportlab table 设置cellstyle枚举,设置单元格padding
    代理工具 v2ra*的使用
    python 开发环境需要安装
    postgres 新增或者更新语句
    python psycopg2 查询结果返回字典类型
    postgres 多个字段匹配查询
    django 执行原生sql形参传递,字段参数传递
    亚马逊接口调用
    python x 开头的字符转码为中文
    postgres 定义变量
  • 原文地址:https://www.cnblogs.com/a972290869/p/4222312.html
Copyright © 2011-2022 走看看