#K86907. Maximum Battery Life

    ID: 36968 Type: Default 1000ms 256MiB

Maximum Battery Life

Maximum Battery Life

You are given a set of batteries, each with a specific battery life value and a corresponding hour limit. Your task is to determine the maximum total battery life achievable without exceeding the total available hours. In other words, you need to choose a subset of batteries such that the sum of their hour limits does not exceed (T), while the sum of their battery life values is maximized. This is a typical 0-1 knapsack problem where the battery life represents the value and the hour limit represents the weight.

inputFormat

The input is given via standard input (stdin) and consists of three lines:

  1. The first line contains two integers (n) and (T) where (n) is the number of batteries and (T) is the total available hours.
  2. The second line contains (n) space-separated integers representing the battery life values.
  3. The third line contains (n) space-separated integers representing the corresponding hour limits.

outputFormat

Output a single integer to standard output (stdout), which is the maximum total battery life that can be obtained without exceeding the total hour limit (T).## sample

4 5
1 4 3 4
2 3 1 5
7