結果
問題 |
No.5 数字のブロック
|
ユーザー |
|
提出日時 | 2019-04-05 12:40:37 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 666 bytes |
コンパイル時間 | 550 ms |
コンパイル使用メモリ | 59,752 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-18 14:17:28 |
合計ジャッジ時間 | 1,686 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
/* No.005 「数字のブロック」 解き方01 */ #include <iostream> #include <algorithm> #define BLOCK_NUM_MAX 10000 int main() { int L; // 大きな箱の幅(1 <= L <= 10000) int N; // ブロックの数(1 <= N <= 10000) int W[BLOCK_NUM_MAX]; // 各ブロックの幅(1 <= W[i] <= L) std::cin >> L >> N; for(int i = 0; i < N; i++) { std::cin >> W[i]; } /* sort */ std::sort(W, W + N); int sum = 0; // 箱に入れたブロックの幅の合計 int answer = 0; // 答え for(int i = 0; i < N; i++) { sum += W[i]; if(sum <= L) { answer++; } else { break; } } std::cout << answer << std::endl; return 0; }