結果
問題 |
No.5 数字のブロック
|
ユーザー |
![]() |
提出日時 | 2018-05-29 14:38:28 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 532 bytes |
コンパイル時間 | 321 ms |
コンパイル使用メモリ | 24,192 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 12:26:20 |
合計ジャッジ時間 | 1,230 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
コンパイルメッセージ
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(i == N - 1) break; } printf("%d\n", i + 1); return 0; }