結果
| 問題 | No.617 Nafmo、買い出しに行く | 
| コンテスト | |
| ユーザー |  るさ | 
| 提出日時 | 2018-05-30 19:23:58 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 17 ms / 2,000 ms | 
| コード長 | 506 bytes | 
| コンパイル時間 | 211 ms | 
| コンパイル使用メモリ | 23,552 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-30 08:19:31 | 
| 合計ジャッジ時間 | 1,296 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:5:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
main.cpp:6:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |     scanf("%d",&k);
      |     ~~~~~^~~~~~~~~
main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         scanf("%d",&w[i]);
      |         ~~~~~^~~~~~~~~~~~
            
            ソースコード
#include <stdio.h>
int main(void){
    int n;
    int k;
    scanf("%d",&n);
    scanf("%d",&k);
    int w[n];
    for(int i=0;i<n;i++){
        scanf("%d",&w[i]);
    }
    int ln=1;
    for(int i=0;i<n;i++){
        ln*=2;
    }
    int maxw=0;
    for(int i=0;i<ln;i++){
        int chk=1;
        int tw=0;
        for(int j=0;j<n;j++){
            tw+=((i & chk)>=1)*w[j];
            chk=chk<<1;
        }
        if((tw>maxw)and(tw<=k)){
            maxw=tw;
        }
    }
    printf("%d",maxw);
}
            
            
            
        