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 = 1e5 + 7 ;
int offset = 1e5 + 7 ;
int n , sum;
int a[N] ;
int dp[552][2*N] ;
int solve(int i , int k){
if(~dp[i][k])return dp[i][k] ;
if(i==n)return (k==offset ? 0 : 1e9) ;
return dp[i][k] = min( min( solve(i+1 , k + a[i]) , solve(i+1 , k - a[i]) ) , solve(i+1 , k) + a[i] ) ;
}
int main(){
memset(dp , -1 , sizeof dp) ;
ios_base::sync_with_stdio(0) ;
cin.tie(0);
// freopen("in.in" ,"r" , stdin) ;
cin>>n ;
for(int i = 0 ;i < n;i++){
cin>>a[i];
sum+=a[i] ;
}
int mn = solve(0 , offset) ;
cout<<(sum - mn) /2 + mn ;
return 0 ;
}
# | 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... |