結果
| 問題 |
No.156 キャンディー・ボックス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-03-07 13:44:33 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 19 ms / 2,000 ms |
| コード長 | 477 bytes |
| コンパイル時間 | 175 ms |
| コンパイル使用メモリ | 21,888 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 15:59:27 |
| 合計ジャッジ時間 | 1,192 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:25:1: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%d %d",&n,&M);
| ^~~~~~~~~~~~~~~~~~~~
main.c:28:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | scanf("%d",&N[i]);
| ^~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<stdlib.h>
int sortfnc(const void *a,const void *b){
if(*(int*)a == *(int*)b){
return 0;
}
if(*(int*)a < *(int*)b)
{return -1;
}
return 1;
}
int main(void){
int n,N[10],M,C,i,total=0;
scanf("%d %d",&n,&M);
for(i=0;i<n;i++){
scanf("%d",&N[i]);
}
qsort(N, n, sizeof(int), sortfnc);
for(i=0;i<n;i++){
while(M>0){
if(N[i]>0){ N[i]--;
M--;
}if(N[i]==0){ total++;
break;
}
}
}
printf("%d",total);
return 0;
}