結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
Elk
|
| 提出日時 | 2018-05-29 14:22:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 565 bytes |
| コンパイル時間 | 137 ms |
| コンパイル使用メモリ | 24,192 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-30 08:01:04 |
| 合計ジャッジ時間 | 1,175 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 29 |
コンパイルメッセージ
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;
}
}
if(N == 1){
printf("%d\n", i);
}else{
printf("%d\n", i - i);
}
return 0;
}
Elk