Submission #370330

#TimeUsernameProblemLanguageResultExecution timeMemory
370330FatihSolakKas (COCI17_kas)C++17
50 / 100
413 ms401020 KiB
#include <bits/stdc++.h> #define N 505 #define M 100005 using namespace std; int dp[N][M]; int arr[N]; void solve(){ for(int i=0;i<N;i++){ for(int j = 0;j<M;j++){ dp[i][j] = -1e9; } } dp[0][0] = 0; int n; cin >> n; for(int i=1;i<=n;i++){ cin >> arr[i]; } if(n <= 13){ assert(0); } sort(arr+1,arr+n+1); int sum = 0; int ans = -1e9; for(int i=1;i<=n;i++){ for(int j=0;j<M;j++){ dp[i][j] = dp[i-1][j]; } for(int j=0;j<M-arr[i];j++){ dp[i][j] = max(dp[i][j],min({dp[i-1][j],dp[i-1][arr[i]],dp[i-1][j+arr[i]]})+arr[i]); } for(int j=0;j<M-arr[i];j++){ dp[i][j+arr[i]] = max(dp[i][j+arr[i]],dp[i-1][j]); } sum+=arr[i]; for(int j=0;j<M;j++){ ans = max(ans,dp[i][j]); } } cout << sum-ans; } 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...