You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool canFillBox(int N, const vector<int>& toys, int c) { // dp[i] indicates if we can fill exactly i capacity with given toys and fillers
vector<bool> dp(N + 1, false); dp[0] = true;
for (int toy : toys) { for (int j = N; j >= toy; --j) { if (dp[j - toy]) { dp[j] = true; } } }
// After using all toys, check if we can fill the remaining space with fillers
return dp[N] || (N <= c); }
int main() { int T; cin >> T; vector<string> res; while (T--) { int N, n, c; cin >> N >> n >> c; vector<int> toys(n); for (int i = 0; i < n; ++i) { cin >> toys[i]; } if (canFillBox(N, toys, c)) { res.push_back("YES"); } else { res.push_back("NO"); } } for(int i = 0; i < res.size(); i++){ cout << res[i] << endl; } return 0; }
|