Submission #960228

#TimeUsernameProblemLanguageResultExecution timeMemory
960228ezzzayAkcija (COCI15_akcija)C++14
80 / 80
30 ms4112 KiB
#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 timeMemoryGrader output
Fetching results...