結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
Elk
|
| 提出日時 | 2018-05-29 13:33:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 502 bytes |
| コンパイル時間 | 136 ms |
| コンパイル使用メモリ | 24,192 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-30 08:00:48 |
| 合計ジャッジ時間 | 1,087 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d%d\n", &box_width, &N);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:14:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d", &box[i]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b){
return *(int *)a - *(int *)b;
}
int main(){
int box_width, N, box[10000];
int i, cnt = 0;
scanf("%d%d\n", &box_width, &N);
for(i = 0; i < N; i++){
scanf("%d", &box[i]);
}
qsort(box, N, sizeof(int), comp);
for(i = 0; i < N; i++){
cnt += box[i];
if(cnt > box_width){
i--;
break;
}
}
printf("%d\n", i + 1);
return 0;
}
Elk