結果
問題 | No.156 キャンディー・ボックス |
ユーザー |
![]() |
提出日時 | 2015-02-26 23:24:55 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 443 bytes |
コンパイル時間 | 264 ms |
コンパイル使用メモリ | 36,712 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 08:38:15 |
合計ジャッジ時間 | 1,165 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:6:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d %d", &N, &M); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%d", cs+i); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <cstdio> #include <algorithm> int main(){ int N, M; scanf("%d %d", &N, &M); int cs[100]; for(int i=1;i<=N;i++){ scanf("%d", cs+i); } std::sort(cs+1, cs+1+N); int res = 0; for(int i=1;i<=N;i++){ if(cs[i] >= M){ if(cs[i] == M){res = i;} else{res = i-1;} break; }else{ M -= cs[i]; } } printf("%d\n", res); }