题解 | #Knapsack Problem#
Knapsack Problem
https://ac.nowcoder.com/acm/problem/13882
遍历求和
#include <iostream> using namespace std; int main() { int T; cin >> T; while (T--) { int n, w, c; cin >> n >> w >> c; int wc[2 * n]; for (int i = 0; i < 2 * n; i++) { cin >> wc[i]; } int wtotal = 0, ctotal = 0; for (int i = 0; i < n; i++) { wtotal += wc[i]; ctotal += wc[i + n]; } if (wtotal > w || ctotal > c) { cout << "NO" << endl; } else { cout << "YES" << endl; } } return 0; }