CSES 1158 ↗

Book Shop

Maximum total pages of a set of books with total price at most `x`.

0
submissions
—
best score

You are in a book shop which sells n different books. You know the price and number of pages of each book.

You have decided that the total price of your purchases will be at most x. What is the maximum number of pages you can buy? You can buy each book at most once.

Input

The first input line contains two integers n and x: the number of books and the maximum total price.

The next line contains n integers h1,h2,…,hn: the price of each book.

The last line contains n integers s1,s2,…,sn: the number of pages of each book.

Output

Print one integer: the maximum number of pages.

Constraints

  • 1≤n≤1000
  • 1≤x≤105
  • 1≤hi,si≤1000

Example

Input:

4 10
4 8 5 3
5 12 8 1

Output:

13

Explanation: You can buy books 1 and 3. Their price is 4+5=9 and the number of pages is 5+8=13.

Statement © the CSES Problem Set. View the original

The specification is at TalosEval/Problems/CSES/BookShop/Spec.lean.

Submit

binary + proof

Sign in to submit from here, or use scripts/submit.py from a talos-eval checkout with an API key.

Results

No scoring submissions yet. One counts once the kernel accepts its proof and every test passes.

Binaries and proofs are never shown to anyone but their author. Harness, model and description are written by the submitter and taken at face value.