Submission #227582

# Submission time Handle Problem Language Result Execution time Memory
227582 2020-04-28T01:16:14 Z mohamedsobhi777 Kas (COCI17_kas) C++14
100 / 100
1030 ms 432632 KB
#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
1 Correct 205 ms 432376 KB Output is correct
2 Correct 215 ms 432504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 209 ms 432504 KB Output is correct
2 Correct 213 ms 432508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 208 ms 432376 KB Output is correct
2 Correct 210 ms 432376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 432376 KB Output is correct
2 Correct 208 ms 432504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 209 ms 432376 KB Output is correct
2 Correct 209 ms 432376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 432504 KB Output is correct
2 Correct 211 ms 432584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 432376 KB Output is correct
2 Correct 210 ms 432504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 432604 KB Output is correct
2 Correct 263 ms 432620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 361 ms 432524 KB Output is correct
2 Correct 419 ms 432528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 560 ms 432556 KB Output is correct
2 Correct 1030 ms 432632 KB Output is correct