#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int n,tot;
int arr[305];
int dp[205][205],dp2[205][205];
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i=1;i<=n;i++){
cin >> arr[i];
tot += 3LL*arr[i];
}
for(int j=0;j<=200;j++){
for(int k=0;k<=200;k++){
dp[j][k] = -2e9;
dp2[j][k] = -2e9;
}
}
dp[0][0] = 0;
for(int i=1;i<=n;i++){
for(int j=0;j<=200;j++){
for(int k=0;k<=200;k++){
int x = min(arr[i],min(j,k));
dp2[k-x][arr[i]-x] = max(dp2[k-x][arr[i]-x],dp[j][k]+x*2LL);
}
}
for(int j=200;j>=1;j--){
for(int k=200;k>=1;k--){
dp2[j-1][k-1] = max(dp2[j-1][k-1],dp2[j][k]+1LL);
}
}
for(int j=0;j<=200;j++){
for(int k=0;k<=200;k++){
dp[j][k] = dp2[j][k];
dp2[j][k] = -2e9;
}
}
}
int maxi=0;
for(int j=0;j<=200;j++){
for(int k=0;k<=200;k++){
maxi = max(maxi,dp[j][k]);
}
}
cout << tot-maxi << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
852 KB |
Output is correct |
3 |
Correct |
2 ms |
980 KB |
Output is correct |
4 |
Correct |
13 ms |
980 KB |
Output is correct |
5 |
Correct |
2 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
852 KB |
Output is correct |
7 |
Correct |
3 ms |
968 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
3 ms |
980 KB |
Output is correct |
10 |
Correct |
5 ms |
852 KB |
Output is correct |
11 |
Correct |
30 ms |
964 KB |
Output is correct |
12 |
Correct |
6 ms |
852 KB |
Output is correct |
13 |
Correct |
29 ms |
952 KB |
Output is correct |
14 |
Correct |
44 ms |
952 KB |
Output is correct |
15 |
Correct |
49 ms |
968 KB |
Output is correct |
16 |
Correct |
42 ms |
960 KB |
Output is correct |
17 |
Correct |
56 ms |
852 KB |
Output is correct |
18 |
Correct |
62 ms |
852 KB |
Output is correct |
19 |
Correct |
53 ms |
964 KB |
Output is correct |
20 |
Correct |
57 ms |
960 KB |
Output is correct |