zoukankan      html  css  js  c++  java
  • B

    B - Free Market
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status
    Appoint description: 

    Description

    John Doe has recently found a "Free Market" in his city — that is the place where you can exchange some of your possessions for other things for free.

    John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that each item is one of a kind and that means that you cannot exchange set {a, b} for set {v, a}. However, you can always exchange set x for any set y, unless there is item p, such that p occurs in x and p occurs in y.

    For each item, John knows its value ci. John's sense of justice doesn't let him exchange a set of items x for a set of items y, if s(x) + d < s(y) (s(x) is the total price of items in the set x).

    During one day John can exchange only one set of items for something else. Initially, he has no items. John wants to get a set of items with the maximum total price. Find the cost of such set and the minimum number of days John can get it in.

    Input

    The first line contains two space-separated integers nd (1 ≤ n ≤ 501 ≤ d ≤ 104) — the number of items on the market and John's sense of justice value, correspondingly. The second line contains n space-separated integers ci (1 ≤ ci ≤ 104).

    Output

    Print two space-separated integers: the maximum possible price in the set of items John can get and the minimum number of days needed to get such set.

    Sample Input

    Input
    3 2
    1 3 10
    Output
    4 3
    Input
    3 5
    1 2 3
    Output
    6 2
    Input
    10 10000
    10000 9999 1 10000 10000 10000 1 2 3 4
    Output
    50010 6
     
    const int INF = 1000000000;
    const double eps = 1e-8;
    const int maxn = 511010;
    int a[maxn];
    int dp[maxn];
    int main() 
    {
        //freopen("in.txt","r",stdin);
        int n,d;
        while(cin>>n>>d)
        {
            repf(i,1,n) scanf("%d",&a[i]);
            clr(dp);
            dp[0] = 1;
            repf(i,1,n)
            {
                repd(j,50*10000,0)
                {
                    if(dp[j] && j + a[i] <= 50*10000)
                        dp[j + a[i]] = 1;
                }
            }
            int sum = 0,num = 0;
            while(1)
            {
                int flag = 0;
                repd(i,sum + d,sum + 1)
                {
                    if(i > 50*10000) continue;
                    if(dp[i])
                    {
                        sum = i;
                        num++;
                        flag = 1;
                        break;
                    }
                }
                if(flag == 0)
                    break;
            }
            cout<<sum<<" "<<num<<endl;
        }
        return 0;
    }
  • 相关阅读:
    SQL多表合并查询结果
    无法访问请求的页面,因为该页的数据的相关配置数据无效
    网站运行的时候编译成功但是程序浏览器的页面不会显示怎么回事啊
    EasyUI 在textbox里面输入数据敲回车后查询和普通在textbox输入数据敲回车的区别
    搭建Go开发及调试环境(LiteIDE + GoClipse) -- Windows篇
    Python开发工具安装
    jQuery 插件写法2
    jQuery插件面向对象开发
    Jquery插件学习
    Maven 仓库
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3452992.html
Copyright © 2011-2022 走看看