結果
問題 | No.5 数字のブロック |
ユーザー |
|
提出日時 | 2018-02-01 13:34:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 462 bytes |
コンパイル時間 | 733 ms |
コンパイル使用メモリ | 65,300 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 12:04:06 |
合計ジャッジ時間 | 1,693 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include <stdio.h> #include <iostream> #include <vector> #include <algorithm> using namespace std; int L; int N; vector<int> W; int solve(int n, int l, int cnt) { if (l > L) return cnt - 1; if (n >= N || l == L) return cnt; return solve(n+1, l+W[n], cnt+1); } int main() { cin >> L; cin >> N; W.resize(N); for (int n = 0; n < N; n++) { cin >> W[n]; } sort(W.begin(), W.end()); cout << solve(0, 0, 0) << endl; }