CodeForces

来源:互联网 发布:大数据架构图 编辑:程序博客网 时间:2024/06/03 17:17
D. Free Market
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
input
3 21 3 10
output
4 3
input
3 51 2 3
output
6 2
input
10 1000010000 9999 1 10000 10000 10000 1 2 3 4
output
50010 6
Note

In the first sample John can act like this:

  • Take the first item (1 - 0 ≤ 2).
  • Exchange the first item for the second one (3 - 1 ≤ 2).
  • Take the first item (1 - 0 ≤ 2).

先把所有可能交换出来的状态递推出来,然后贪心找一遍

重要的是不要考虑交换那个物品,要整体考虑,我当前这个状态(a)可以通过换某些东西,换到【a+1,a+d】中的某个状态

#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<string>#include<algorithm>#include<queue>#include<vector>#include<map>#include<set>#define eps 1e-9#define PI 3.141592653589793#define bs 1000000007#define bsize 256#define MEM(a) memset(a,0,sizeof(a))#define inf 0x3f3f3f3f#define rep(i,be,n) for(i=be;i<n;i++)typedef long long ll;using namespace std;int dp[550005];int main(){int n,d,c,i,j,x,flog;scanf("%d %d",&n,&d);dp[0]=1;//1表示i这个状态出现过,0表示没出现for(i=0;i<n;i++){scanf("%d",&c);for(j=500000;j>=c;j--){dp[j]|=dp[j-c];}}int day=0;x=0;while(1){flog=0;for(j=x+d;j>x;j--){if(dp[j]){flog=1;day++;x=j;break;}}if(!flog)break;}printf("%d %d\n",x,day); }




0 0