Submission #370335

# Submission time Handle Problem Language Result Execution time Memory
370335 2021-02-23T19:50:56 Z FatihSolak Kas (COCI17_kas) C++17
100 / 100
208 ms 196460 KB
#include <bits/stdc++.h>
#define N 505
#define M 100005
using namespace std;
int dp[N][M];
int arr[N];
void solve(){
    for(int j = 1;j<M;j++){
        dp[0][j] = -1e9;
    }
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> arr[i];
    }
    int sum = 0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<M;j++){
            dp[i][j] = max(dp[i-1][j],max(dp[i-1][j+arr[i]],dp[i-1][abs(j-arr[i])])+arr[i]);
        }
        sum+=arr[i];
    }
    cout << sum-dp[n][0]/2;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4588 KB Output is correct
2 Correct 5 ms 4588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4588 KB Output is correct
2 Correct 5 ms 4588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4588 KB Output is correct
2 Correct 5 ms 5244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5484 KB Output is correct
2 Correct 6 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5868 KB Output is correct
2 Correct 8 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 14444 KB Output is correct
2 Correct 18 ms 16364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 18388 KB Output is correct
2 Correct 21 ms 20332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 79024 KB Output is correct
2 Correct 117 ms 98540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 118124 KB Output is correct
2 Correct 171 ms 157292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 191 ms 176872 KB Output is correct
2 Correct 208 ms 196460 KB Output is correct