結果
問題 | No.5 数字のブロック |
ユーザー |
![]() |
提出日時 | 2015-05-09 10:39:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 362 bytes |
コンパイル時間 | 333 ms |
コンパイル使用メモリ | 36,704 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-17 22:42:11 |
合計ジャッジ時間 | 1,074 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%d", &L); | ~~~~~^~~~~~~~~~ main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:12:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d", &W[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <algorithm> using namespace std; int main(){ int L, N, W[10000]; int sum, count; sum = count = 0; scanf("%d", &L); scanf("%d", &N); for (int i = 0; i < N; i++){ scanf("%d", &W[i]); } sort(W, W + N); for (int i = 0; i < N; i++){ sum += W[i]; if (sum <= L) count++; else break; } printf("%d\n", count); return 0; }