結果

問題 No.617 Nafmo、買い出しに行く
ユーザー hiro_metal_corehiro_metal_core
提出日時 2017-12-19 22:45:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 719 ms
コンパイル使用メモリ 51,448 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-22 07:07:28
合計ジャッジ時間 1,882 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,388 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 6 ms
4,384 KB
testcase_07 AC 7 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 6 ms
4,384 KB
testcase_11 AC 7 ms
4,384 KB
testcase_12 AC 6 ms
4,384 KB
testcase_13 AC 6 ms
4,384 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:18: warning: ‘i’ is used uninitialized in this function [-Wuninitialized]
     for(int i; i < N; i++){
                ~~^~~

ソースコード

diff #

#include<cstdio>
#include<iostream>
using namespace std;

int bin_search(int *a, int item_index, int rest_weight, int N)
{
    int res1, res2;

    if(item_index == N){
        return 0;
    }
    else if(rest_weight < a[item_index]){
        return bin_search(a, item_index + 1, rest_weight, N);
    }
    else{
        res1 = bin_search(a, item_index + 1, rest_weight, N);
        res2 = bin_search(a, item_index + 1, rest_weight - a[item_index], N) + a[item_index];
        return max(res1, res2);
    }
}

int main()
{
    int N, K;
    scanf("%d %d", &N, &K);
    int a[N];
    for(int i; i < N; i++){
        scanf("%d", &a[i]);
    }

    printf("%d\n", bin_search(a, 0, K, N));

    return 0;
}
0