結果
問題 |
No.156 キャンディー・ボックス
|
ユーザー |
![]() |
提出日時 | 2025-03-14 10:27:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 602 bytes |
コンパイル時間 | 535 ms |
コンパイル使用メモリ | 28,160 KB |
実行使用メモリ | 7,324 KB |
最終ジャッジ日時 | 2025-03-14 10:27:15 |
合計ジャッジ時間 | 2,068 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 4 |
other | AC * 13 WA * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d%d",&box,&sum); | ~~~~~^~~~~~~~~~~~~~~~~~ main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%d",&candy[i]); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> int main(){ // 箱の数・飴をとる数 int box,sum; scanf("%d%d",&box,&sum); // 各々の箱に入っている飴の数 int candy[box]; // 一番少ない飴の数 int min = 0; // 一番少ない飴の要素数 int element = 0; for(int i = 0;i < box;i++){ scanf("%d",&candy[i]); } for(int j = 0;j < sum;j++){ for(int i = 0;i < box;i++){ if((i == 0 || min > candy[i]) && candy[i] > 0){ min = candy[i]; element = i; } } candy[element] -= 1; } int ans = 0; for(int i = 0;i < box;i++){ if(candy[i] == 0){ ans++; } } printf("%d",ans); }