結果
| 問題 |
No.156 キャンディー・ボックス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-20 23:51:15 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 451 bytes |
| コンパイル時間 | 298 ms |
| コンパイル使用メモリ | 20,608 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-06 05:54:38 |
| 合計ジャッジ時間 | 1,263 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 3 |
| other | AC * 16 WA * 14 |
コンパイルメッセージ
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 = 0; j < n - i; 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;
}