結果
| 問題 |
No.156 キャンディー・ボックス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-03-15 23:18:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 848 bytes |
| コンパイル時間 | 279 ms |
| コンパイル使用メモリ | 36,992 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 16:15:20 |
| 合計ジャッジ時間 | 1,153 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%d",&C[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <algorithm>
int N,M;
int main(){
//input
scanf("%d %d",&N,&M);
int C[N];
for (int i = 0;i < N;i++){
scanf("%d",&C[i]);
}
//sort array C
std::sort(C,C+N);
//take candy
int candyTotal = 0;
for (int i = 0;i < N;i++){
if (candyTotal < M){
if (M-candyTotal <= C[i]){
int tmp = M-candyTotal;
candyTotal += tmp;
C[i] -= tmp;
}else{
candyTotal += C[i];
C[i] = 0;
}
}else{
break;
}
}
//count empty box
int emptyTotal = 0;
for (int i = 0;i < N;i++){
if (C[i] == 0){
emptyTotal++;
}else{
break;
}
}
//output
printf("%d\n",emptyTotal);
return 0;
}