Submission #5160

#TimeUsernameProblemLanguageResultExecution timeMemory
5160cki86201K blocks (IZhO14_blocks)C++98
100 / 100
220 ms42464 KiB
#include<stdio.h> #include<algorithm> #include<string.h> #include<vector> #include<math.h> #include<stdlib.h> #include<set> #include<ctype.h> using namespace std; #define X first #define Y second typedef long long ll; typedef pair<int,int> Pi; int n, k, inp[100010]; int d[102][100010]; int main() { scanf("%d%d",&n,&k); int i, j; for(i=1;i<=n;i++)scanf("%d",inp+i); for(i=1;i<=n;i++)d[1][i] = max(d[1][i-1], inp[i]); for(i=2;i<=k;i++){ vector <Pi> v; for(j=i;j<=n;j++){ int now = d[i-1][j-1]; while(!v.empty() && v.back().X < inp[j])now = min(now, v.back().Y), v.pop_back(); if(v.empty() || v.back().X + v.back().Y > inp[j] + now)v.push_back(Pi(inp[j],now)); d[i][j] = v.back().X + v.back().Y; } } printf("%d",d[k][n]); 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...