Book Exchange!!
Practice
0 (0 votes)
Jlong21_q8
Problem
82% Success 51 Attempts 50 Points 5s Time Limit 256MB Memory 1024 KB Max Code

As everyone knows, in Nirma their is a culture of book exchange, i.e. every one sells their set of books to their juniors and buys set of books from their seniors. Let's take an example of a studious student Ayush Zaveri who practices the same trend, and as he is from Hiramani(Hostel opposite to Nirma, this is in no way a promotion) he exercises a special benefit that if he gives his set of books to some junior he will get a set of books from his senior for FREE.

Ayush knows that their are in total n types of books (each book is unique and only a single book is available of one kind). He can bring any number of books for giving to the junior and hence receiving any arbitary set of books from senior. Also note that each item is one of a kind and you cannot sell and buy a particular book simultanously. However, he can always sell set X for buying any set Y, unless there is a book p, such that p occurs in both set X and Y.

For each book, Ayush knows its cost ci. Ayush's sense of justice(as he is a model student) doesn't let him exchange(giving and receiving) a set of items X for a set of items Y, if cost(Y) - cost(X)  > d  (cost(x) is the total cost of books in the set x).

During one day Ayush can exchange only one set of books for something else. Initially, he has no books(because he was fond of using PDF's). Ayush wants to get a set of books with the maximum total cost (because who doesn't like some extra cash). He asked you to help him to find the minimum number of days in which he can make the maximum total cost.

 

INPUT:

In the first line you have two space seperated integers n(total number of different books) and d(the parameter).(1 <= n <= 50, 1 <= d <= 10000).

In the second line you will have n space seperated integers ci(cost of each book) (1 <= ci <= 10000).

 

OUTPUT:

Print two space-separated integers, the maximum possible total cost in the set of books Ayush can get and the minimum number of days needed to get such set.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
RecursionHardMemoizationRecruitAlgorithmsGrammar-VerifiedApprovedDynamic programming
Points:50
Tags:
CombinatoricsDynamic programmingStringHardDynamic programming