結果
| 問題 |
No.156 キャンディー・ボックス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-20 23:43:38 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 449 bytes |
| コンパイル時間 | 95 ms |
| コンパイル使用メモリ | 21,120 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-06 05:53:55 |
| 合計ジャッジ時間 | 1,031 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 WA * 1 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:9: warning: ignoring return value of ‘fscanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
7 | fscanf(stdin, "%d %ld", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:9:17: warning: ignoring return value of ‘fscanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | fscanf(stdin, "%ld", &c[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
int main(void) {
// your code goes here
int n, i, j;
long m, c[10], tmp;
fscanf(stdin, "%d %ld", &n, &m);
for (i = 0; i < n; i++)
fscanf(stdin, "%ld", &c[i]);
for(i = 0; i < n; i++){
for(j = i; j < n -1; j++){
if(c[j] > c[j+1]){
tmp = c[j];
c[j] = c[j+1];
c[j+1] = tmp;
}
}
}
j = 0;
for(i = 0; i < n; i++){
if(m >= c[i]){
m -= c[i];
j++;
}else break;
}
printf("%d\n", j);
return 0;
}