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