#K89172. Maximize Lantern Brightness

    ID: 37472 Type: Default 1000ms 256MiB

Maximize Lantern Brightness

Maximize Lantern Brightness

You are given (N) lanterns, each with a specific brightness value. Your task is to choose a subset of these lanterns such that the total brightness is maximized, but it does not exceed a given threshold (T). Although additional parameters (M) and an array of power connections are provided, they are not used in the calculation for this task.

Formally, you are provided with brightness values (b_1, b_2, \dots, b_N). Determine the maximum sum (S = \sum_{i \in subset} b_i) satisfying (S \le T). Input is taken from standard input (stdin) and the answer must be printed to standard output (stdout).

inputFormat

The input consists of three lines read from standard input:

  • The first line contains three integers: \(N\) (the number of lanterns), \(M\) (an extra parameter, not used in the calculation), and \(T\) (the brightness threshold).
  • The second line contains \(N\) space-separated integers representing the brightness levels of the lanterns.
  • The third line contains \(N\) space-separated integers representing the power connections (this array is not used in the calculation).

outputFormat

Output a single integer: the maximum possible sum of brightness that does not exceed (T). This result should be printed to standard output (stdout).## sample

5 3 10
2 3 4 1 5
1 2 3 2 1
10