Submission #151543

#TimeUsernameProblemLanguageResultExecution timeMemory
151543tqthangblK blocks (IZhO14_blocks)C++14
53 / 100
1068 ms2524 KiB
#include <bits/stdc++.h> using namespace std; #define taskname "MAXK" #define forinc(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define fordec(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define foreach(i, x) for (auto &i : x) #define ms(x, n) memset(x, n, sizeof(x)) #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define uni(x) (x).erase(unique(all(x)), (x).end()) #define fi first #define se second #define pb push_back #define pf push_front template<typename TH> void _dbg(const char* sdbg, TH h) { cerr << sdbg << " = " << h << "\n"; } template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while (*sdbg != ',') cerr << *sdbg++; cerr << " = " << h << ","; _dbg(sdbg + 1, t...); } #define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define chkpt cerr << "--- Checkpoint here ---\n"; const int N=1e5+5,K=1e2+2; const int64_t LINF=1e18; int n,k,a[N]; int64_t dp[K][N]; void ReadInput() { cin>>n>>k; forinc(i,1,n) cin>>a[i]; } int GetMax(int l,int r) { int res=a[l]; forinc(i,l+1,r) res=max(res,a[i]); return res; } void Solve() { forinc(nGroup,1,k) forinc(i,1,n) dp[nGroup][i]=LINF; int curMax=a[1]; forinc(i,1,n) { curMax=max(curMax,a[i]); dp[1][i]=curMax; } forinc(nGroup,2,k) { forinc(i,nGroup,n) { int curMax=a[i]; fordec(j,i-1,1) { curMax=max(curMax,a[j+1]); if(dp[nGroup-1][j]==LINF) continue; dp[nGroup][i]=min(dp[nGroup][i],dp[nGroup-1][j]+curMax); } } } cout<<dp[k][n]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); // #ifndef ONLINE_JUDGE // freopen(taskname".INP","r",stdin); // #endif // ONLINE_JUDGE ReadInput(); Solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...