# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
960228 | ezzzay | Akcija (COCI15_akcija) | C++14 | 30 ms | 4112 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
int dp[N];
signed main(){
int n;
cin>>n;
vector<int>v;
for(int i=1;i<=n;i++){
int a;
cin>>a;
v.pb(a);
}
sort(v.begin(),v.end(),greater<int>());
dp[1]=v[0];
dp[2]=v[0]+v[1];
for(int i=3;i<=n;i++){
dp[i]=min(dp[i-1]+v[i-1],dp[i-3]+v[i-2]+v[i-3]);
}
cout<<dp[n];
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |