Weapons

After each stage of the video game, the player has the option of buying
weapons using money gathered from killing enemies. The ship can carry a
single copy of each weapon, each of which has a price and a damage rate.
The total damage rate of the ship equals the sum of the damage rate of
its weapons. However, not all weapons are available for purchase at any
given time. Help the player optimize the purchase of weapons to maximize
the damage rate.

Input

The input begins with an integer 1 ≤ N ≤ 1000 representing the number of
weapons. On the next N lines appear the price 1 ≤ P ≤ 1000 and damage
rate 1 ≤ D ≤ 1000 of each weapon.

Several test cases follow. Each test case consists of the player’s money
1 ≤ M ≤ 1000, the number of available weapons 1 ≤ K ≤ N, and the K
indices of the available weapons.

Output

For each test case, a number on a single line representing the maximum
damage rate of weapons that the player can buy with their money.

Problem information

Author: Anders Jonsson

Generation: 2026-01-25T22:27:26.288Z

© Jutge.org, 2006–2026.
https://jutge.org
