Submission #602378

#TimeUsernameProblemLanguageResultExecution timeMemory
602378Doanxem99K blocks (IZhO14_blocks)C++14
0 / 100
38 ms87236 KiB
//Link : //Author: Nguyen Dinh Manh #include <bits/stdc++.h> using namespace std; #define timing "Time collapse : " << fixed << setprecision(3) << 1.000 * clock() / CLOCKS_PER_SEC #define int long long #define ar array< int , 2> #define MASK(i) (1 << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define task "" template<typename T1, typename T2> bool minN(T1 &a, T2 b) {if (a > b) a = b; else return 0; return 1;} template<typename T1, typename T2> bool maxX(T1 &a, T2 b) {if (a < b) a = b; else return 0; return 1;} const int MAX = 100011, INFL = 1e9 + 7, INFLL = 1e18 + 7; int n, f[MAX][111], a[MAX], k; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen(task".inp","r", stdin); freopen(task".out","w",stdout); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } memset(f, 0x3f, sizeof f); f[1][0] = 0; for (int i = 1; i <= n; i++) minN(f[1][i], max(f[1][i - 1], a[i])); for (int i = 2; i <= k; i++) { int minF; stack< ar > s; for (int j = 1; j <= n; j++) { minF = f[i - 1][j - 1]; while (!s.empty() && s.top()[1] <= a[j]) { minN(minF, f[i][s.top()[0]]); s.pop(); } f[i][j] = min(f[i][(s.empty() ? 0 : s.top()[0])], minF + a[i]); s.push({j, a[j]}); } } cout << f[k][n] ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...