This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int S = 1e5 + 10;
int n, a[N];
bitset<N> B[S];
bool dp[S];
int main(){
cin >> n;
int total = 0;
for (int i = 0; i < n; i ++)
cin >> a[i], total += a[i];
sort(a, a + n);
dp[0] = 1;
int mx = 0;
for (int i = 0; i < n; i ++){
for (int sm = total; sm >= a[i]; sm--){
if (!dp[sm - a[i]]) continue;
if (dp[sm]){
bitset<N> b = B[sm - a[i]];
b[i] = 1;
b &= B[sm];
if (!(b.any()))
mx = max(mx, sm);
}
else{
dp[sm] = 1;
B[sm] = B[sm - a[i]];
B[sm][i] = 1;
}
}
}
cout << total - mx << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |