제출 #370311

#제출 시각아이디문제언어결과실행 시간메모리
370311FatihSolakKas (COCI17_kas)C++17
40 / 100
306 ms198144 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]; } 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]); if(dp[i][j] >= 0){ //cout << i << " " << j << " "<< dp[i][j] << endl; } } sum+=arr[i]; } for(int j=0;j<M;j++){ ans = max(ans,dp[n][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...