結果

問題 No.156 キャンディー・ボックス
ユーザー Bantako
提出日時 2017-06-27 22:29:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 503 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 36,812 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 16:04:05
合計ジャッジ時間 1,150 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:4:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    4 | main(){
      | ^~~~
main.cpp: In function ‘int main()’:
main.cpp:7:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |     scanf("%d%d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~
main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         scanf("%d",&C[i]);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<algorithm>
using namespace std;
main(){
    int N,M;
    int C[10];
    scanf("%d%d",&N,&M);
    for(int i = 0;i < N;i++){
        scanf("%d",&C[i]);
    }
    sort(C,C+N);
    int rest = M;//取る残り回数
    int count = 0;
    for(int i = 0;;i++){
        if(C[i] > rest){
            break;
        }else if(C[i] == rest){
            count++;
            break;
        }else{
            rest -= C[i];
            count++;
        }
    }
    printf("%d\n",count);
}
0