Submission #345181

#TimeUsernameProblemLanguageResultExecution timeMemory
345181mansurK blocks (IZhO14_blocks)C++14
32 / 100
1037 ms512 KiB
#include<bits/stdc++.h> using namespace std; #define all(a) a.begin(),a.end() #define ll long long #define pb push_back #define nl '\n' #define popb pop_back() #define sz size() #define ld long double #define ull unsigned long long #define F first #define S second #define fix fixed<<setprecision #define pii pair<int,int> #define E exit (0) #define int long long const int inf=1e9; int c[100001],mn=inf,n; void r(int pos,int k,int sum=0,int mx=0) { if (pos==n+1&&k>0) { return; } if (k==0&&pos==n+1) { mn=min(mn,sum); return; } if (k<0) { return; } r(pos+1,k-1,sum+c[pos],c[pos]); r(pos+1,k,sum-mx+max(mx,c[pos]),max(mx,c[pos])); } signed main() { //freopen("planting.in","r",stdin); //freopen("planting.out","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); int k; cin>>n>>k; int s[n+2]; s[n+1]=0; for (int i=1;i<=n;i++) { cin>>c[i]; } for (int i=n;i>=1;i--) { s[i]=max(s[i+1],c[i]); } if (k<=5) { int mn=inf; if (k==1) { mn=s[1]; } for (int i=1,mx1=0;i<n;i++) { mx1=max(mx1,c[i]); if (k>2) { for (int j=i+1,mx2=0;j<n;j++) { mx2=max(mx2,c[j]); if (k>3) { for (int d=j+1,mx3=0;d<n;d++) { mx3=max(mx3,c[d]); if (k>4) { for (int f=d+1,mx4=0;f<n;f++) { mx4=max(mx4,c[f]); mn=min(mn,mx4+mx3+mx2+mx1+s[f+1]); } }else { mn=min(mn,mx3+mx2+mx1+s[d+1]); } } }else { mn=min(mn,mx1+mx2+s[j+1]); } } }else { mn=min(mn,mx1+s[i+1]); } } cout<<mn; return 0; } r(1,k); cout<<mn; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...