提出 #514492
ソースコード 拡げる
<?php
fscanf(STDIN,"%d",$N);
fscanf(STDIN,"%d",$T);
//$N = 6;
//$T = 92;
$A = array(31,15,26,35,97,32);
$B = array(4,9,5,8,9,3);
$sum = 0;
$sum2 = 0;
$count = 0;
//$Bの合計値と$Tの比較
foreach ($B as $value) {
$sum += $value;
}
if ($sum > $T) {
echo -1;
exit();
}
while (true) {
$count ++;
//初期化
$sum2 = 0;
$arr = array();
$arr2 = array();
$arr3 = array();
//$Aの中の最大値候補を探す
$arr = array_keys($A,max($A));
//var_dump($arr);
//$Bの中の最小値候補を探す
foreach ($arr as $value) {
$arr2[$value] = $B[$value];
}
$arr3 = array_keys($arr2,min($arr2));
//var_dump($arr3);
//$Aと$Bの値を置換する
$A[$arr3[0]] = $B[$arr3[0]];
//置換した後の$Aの合計値が$Tの値より大きいか比較
foreach ($A as $value) {
$sum2 += $value;
}
if ($sum2 <= $T) {
break;
}
//echo $count;
}
echo $count;
?>
提出情報
ジャッジ結果
| セット名 | Sample | Dataset1 | Dataset2 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 30 | 0 / 70 | ||||||
| 結果 |
|
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt |
| Dataset1 | sample-01, sample-02, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt |
| Dataset2 | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01-01.txt | WA | 52 ms | 4436 KiB |
| 01-02.txt | WA | 49 ms | 4484 KiB |
| 01-03.txt | WA | 49 ms | 4484 KiB |
| 01-04.txt | WA | 49 ms | 4568 KiB |
| 01-05.txt | WA | 52 ms | 4492 KiB |
| 01-06.txt | WA | 51 ms | 4496 KiB |
| 01-07.txt | WA | 51 ms | 4500 KiB |
| 01-08.txt | WA | 48 ms | 4492 KiB |
| 01-09.txt | WA | 50 ms | 4488 KiB |
| 01-10.txt | WA | 50 ms | 4496 KiB |
| 01-11.txt | WA | 49 ms | 4496 KiB |
| 01-12.txt | WA | 51 ms | 4492 KiB |
| 01-13.txt | WA | 51 ms | 4496 KiB |
| 01-14.txt | WA | 50 ms | 4492 KiB |
| 01-15.txt | WA | 51 ms | 4496 KiB |
| 02-01.txt | WA | 50 ms | 4492 KiB |
| 02-02.txt | WA | 50 ms | 4484 KiB |
| 02-03.txt | WA | 48 ms | 4572 KiB |
| 02-04.txt | WA | 51 ms | 4424 KiB |
| 02-05.txt | WA | 50 ms | 4480 KiB |
| 02-06.txt | WA | 50 ms | 4488 KiB |
| 02-07.txt | WA | 50 ms | 4416 KiB |
| 02-08.txt | WA | 50 ms | 4544 KiB |
| 02-09.txt | WA | 50 ms | 4492 KiB |
| 02-10.txt | WA | 50 ms | 4484 KiB |
| 02-11.txt | WA | 50 ms | 4488 KiB |
| 02-12.txt | WA | 53 ms | 4484 KiB |
| 02-13.txt | WA | 52 ms | 4496 KiB |
| 02-14.txt | WA | 52 ms | 4492 KiB |
| 02-15.txt | WA | 50 ms | 4492 KiB |
| 02-16.txt | WA | 52 ms | 4492 KiB |
| sample-01.txt | WA | 51 ms | 4496 KiB |
| sample-02.txt | WA | 52 ms | 4492 KiB |
| sample-03.txt | WA | 51 ms | 4496 KiB |
| sample-04.txt | WA | 52 ms | 4496 KiB |
| sample-05.txt | WA | 52 ms | 4488 KiB |