<?php
$price_list_count = (int)$tokens[0];
for($i = 0; $i < $price_list_count; $i++)
{
}
$campain_count = (int)$tokens[1];
for($i = 0; $i < $campain_count; $i++)
{
}
$list = NULL;
foreach($campain_list as $campain)
{
$list = knaposack($list,$campain,$price_list);
show_total_price($list,$campain);
}
function knaposack($list,$campain,$price_list)
{
$max = $campain + 1;
if($list == NULL)
foreach($price_list as $price)
{
for($i = $price; $i <= $max; $i++)
{
if(!isset($list[$i - $price])) $list[$i - $price] = 0;
$list[$i] = 0;
$old_price = $list[$i - $price];
$new_price = $old_price + $price;
if($new_price > $list[$i])
{
$list[$i] = $new_price;
}
}
}
return $list;
}
function show_total_price($list,$campain_price)
{
echo $list[$campain_price] . "\n";
}
?>
PD9waHAKJGxpbmUgPSB0cmltKGZnZXRzKFNURElOKSk7CiR0b2tlbnMgPSBleHBsb2RlKCIgIiwkbGluZSk7CiRwcmljZV9saXN0X2NvdW50ID0gKGludCkkdG9rZW5zWzBdOwokcHJpY2VfbGlzdCA9IGFycmF5KCk7CmZvcigkaSA9IDA7ICRpIDwgJHByaWNlX2xpc3RfY291bnQ7ICRpKyspCnsKCSRsaW5lID0gdHJpbShmZ2V0cyhTVERJTikpOwoJYXJyYXlfcHVzaCgkcHJpY2VfbGlzdCwoaW50KSRsaW5lKTsKfQpzb3J0KCRwcmljZV9saXN0KTsKCiRjYW1wYWluX2NvdW50ID0gKGludCkkdG9rZW5zWzFdOwokY2FtcGFpbl9saXN0ID0gYXJyYXkoKTsKZm9yKCRpID0gMDsgJGkgPCAkY2FtcGFpbl9jb3VudDsgJGkrKykKewoJJGxpbmUgPSB0cmltKGZnZXRzKFNURElOKSk7CglhcnJheV9wdXNoKCRjYW1wYWluX2xpc3QsKGludCkkbGluZSk7Cn0KCiRsaXN0ID0gTlVMTDsKZm9yZWFjaCgkY2FtcGFpbl9saXN0IGFzICRjYW1wYWluKQp7CgkkbGlzdCA9IGtuYXBvc2FjaygkbGlzdCwkY2FtcGFpbiwkcHJpY2VfbGl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