提交时间:2023-04-08 08:49:44
运行 ID: 73615
#include <bits/stdc++.h> using namespace std; int n; int main() { while (cin >> n) { int a[105] = {0}; int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } int dp[10005] = {0}; for (int i = 0; i < n; i++) { for (int j = sum; j >= a[i]; j--) { dp[j] = max(dp[j], dp[j - a[i]] + a[i]); } } int flag = 0; for (int i = 1; i <= sum; i++) { if (dp[i] != i) { flag = 1; cout << i << endl; break; } } if (!flag) cout << sum + 1 << endl; } return 0; }