結果
問題 |
No.5 数字のブロック
|
ユーザー |
![]() |
提出日時 | 2025-03-26 14:54:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 163 ms / 5,000 ms |
コード長 | 700 bytes |
コンパイル時間 | 353 ms |
コンパイル使用メモリ | 29,312 KB |
実行使用メモリ | 7,324 KB |
最終ジャッジ日時 | 2025-03-26 14:54:38 |
合計ジャッジ時間 | 2,819 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:7:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 7 | scanf("%d", &bigbox); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:9:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%d", &len); | ~~~~~^~~~~~~~~~~~ main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf("%d",&val[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <stdlib.h> int main(void){ // 大きい箱 int bigbox = 0; scanf("%d", &bigbox); int len = 0; scanf("%d", &len); int val[len]; for(int i = 0;i < len;i++){ scanf("%d",&val[i]); } int *p = val; for (int i = 0; i < len; i++) { for (int j = 0; j < len; j++) { //比較元より大きければ入れ替える if (p[i] < p[j]) { int x = p[j]; p[j] = p[i]; p[i] = x; } } } int sum = 0; int count = 0; while(sum < bigbox && count < len){ sum += p[count]; count++; } if(sum <= bigbox){ printf("%d",count); }else{ printf("%d",count - 1); } }