#include <bits/stdc++.h>
#define foreach for
#define in :
using namespace std;
typedef long long ll;
long long MODULO = 998244353;
/*
Konichiwa
Konichiwa
Ara ~~ ara
Bob no taisuki - Shinobu Kocho
* * * * *
* *
* *
* * I love SHINOBU <3 <3 <3
* *
* *
* * * * *
*/
/*
_________________________
Author : Bob15324
_________________________
*/
/*
okay i'm hoping that somebody pray for me
I'm praying that somebody hope for me
I'm staying where nobody 'posed to be
p-p-posted
being a wreak of emotions
ready to go whenever just let me know
the road is long so put the pedal into the floor
the enemy's on my trail
my energy unavailble
Imma tell em hasta luego
they wanna plot on my trot to the top
I've been outta shape thinking out the box I'm an astronaut
i balsted off the planet rock to cause catastrophe and it matters
more because i had it not
had i thought about wreaking havoc on an opposition
kinda shocking they wanted static
with precision i'm automatic quarterback
i ain't talking sacking pack itpack it up i don't panic
who the baddest it doesn't matter cause we at ya throat
*/
// EVERYBODY WANT TO BE MY ENEMY
template<class X , class Y>
bool Minimize(X & x , Y y)
{
if( x == -1|| (x >y && y >= 0 ) )
{
x = y;
return true;
}
return false;
}
template<class X , class Y>
bool Maximize(X & x , Y y)
{
if( x < y)
{
x = y;
return true;
}
return false;
}
template<class X , class Y>
void Add(X &x , Y y )
{
x += y;
if(x >= MODULO)
{
x -= MODULO;
}
}
template<class X , class Y>
void Sub(X &x ,Y y)
{
x -= y;
if(x < 0)
{
x += MODULO;
}
}
/* End of templates. Let's see what do we have here */
const int N = 1e5+1;
const int K = 1e2+1;
int n , k , a[N];
int dp[K][N];
void Prepare()
{
}
void Input()
{
scanf("%d%d" , &n , &k);
for(int i = 1 ; i <= n ; i++)
{
scanf("%d" , &a[i]);
}
}
void Process()
{
memset(dp , 1e9+7 , sizeof(dp));
dp[1][0] = 0;
for(int i = 1 ; i <= n ; i++)
{
dp[1][i] = max(dp[1][i-1] , a[i]);
}
for(int i = 2 ; i <= k ; i++)
{
stack<pair<int ,int >>s;
for(int j = i ; j <= n ; j++)
{
int minn = dp[i-1][j-1];
while(!s.empty() && a[s.top().second] <= a[j])
{
minn = min(minn , s.top().first);
s.pop();
}
dp[i][j] = min(dp[i][s.empty() ? 0 : s.top().second] , minn + a[j]);
s.push(make_pair(minn , j));
}
}
printf("%d" , dp[k][n]);
}
int main()
{
int test;
test = 1;
Prepare();
while(test--)
{
Input();
Process();
}
return 0;
}
//Ehem. My code is amazing. Pay me 2$.Thank you.
Compilation message
blocks.cpp: In function 'void Input()':
blocks.cpp:109:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
109 | scanf("%d%d" , &n , &k);
| ~~~~~^~~~~~~~~~~~~~~~~~
blocks.cpp:112:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
112 | scanf("%d" , &a[i]);
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
39764 KB |
Output is correct |
2 |
Correct |
18 ms |
39728 KB |
Output is correct |
3 |
Correct |
17 ms |
39780 KB |
Output is correct |
4 |
Correct |
17 ms |
39764 KB |
Output is correct |
5 |
Correct |
16 ms |
39736 KB |
Output is correct |
6 |
Correct |
18 ms |
39824 KB |
Output is correct |
7 |
Correct |
18 ms |
39816 KB |
Output is correct |
8 |
Correct |
20 ms |
39828 KB |
Output is correct |
9 |
Correct |
17 ms |
39840 KB |
Output is correct |
10 |
Correct |
17 ms |
39728 KB |
Output is correct |
11 |
Correct |
17 ms |
39764 KB |
Output is correct |
12 |
Correct |
18 ms |
39764 KB |
Output is correct |
13 |
Correct |
19 ms |
39824 KB |
Output is correct |
14 |
Correct |
19 ms |
39764 KB |
Output is correct |
15 |
Correct |
18 ms |
39736 KB |
Output is correct |
16 |
Correct |
19 ms |
39724 KB |
Output is correct |
17 |
Correct |
22 ms |
39708 KB |
Output is correct |
18 |
Correct |
17 ms |
39728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
39764 KB |
Output is correct |
2 |
Correct |
18 ms |
39724 KB |
Output is correct |
3 |
Correct |
19 ms |
39756 KB |
Output is correct |
4 |
Correct |
17 ms |
39816 KB |
Output is correct |
5 |
Correct |
18 ms |
39724 KB |
Output is correct |
6 |
Correct |
18 ms |
39764 KB |
Output is correct |
7 |
Correct |
17 ms |
39820 KB |
Output is correct |
8 |
Correct |
23 ms |
39740 KB |
Output is correct |
9 |
Correct |
17 ms |
39748 KB |
Output is correct |
10 |
Correct |
17 ms |
39756 KB |
Output is correct |
11 |
Correct |
20 ms |
39816 KB |
Output is correct |
12 |
Correct |
23 ms |
39784 KB |
Output is correct |
13 |
Correct |
17 ms |
39840 KB |
Output is correct |
14 |
Correct |
17 ms |
39752 KB |
Output is correct |
15 |
Correct |
17 ms |
39764 KB |
Output is correct |
16 |
Correct |
17 ms |
39736 KB |
Output is correct |
17 |
Correct |
17 ms |
39764 KB |
Output is correct |
18 |
Correct |
17 ms |
39788 KB |
Output is correct |
19 |
Correct |
17 ms |
39732 KB |
Output is correct |
20 |
Correct |
17 ms |
39764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
39764 KB |
Output is correct |
2 |
Correct |
18 ms |
39728 KB |
Output is correct |
3 |
Correct |
17 ms |
39780 KB |
Output is correct |
4 |
Correct |
17 ms |
39764 KB |
Output is correct |
5 |
Correct |
16 ms |
39736 KB |
Output is correct |
6 |
Correct |
18 ms |
39824 KB |
Output is correct |
7 |
Correct |
18 ms |
39816 KB |
Output is correct |
8 |
Correct |
20 ms |
39828 KB |
Output is correct |
9 |
Correct |
17 ms |
39840 KB |
Output is correct |
10 |
Correct |
17 ms |
39728 KB |
Output is correct |
11 |
Correct |
17 ms |
39764 KB |
Output is correct |
12 |
Correct |
18 ms |
39764 KB |
Output is correct |
13 |
Correct |
19 ms |
39824 KB |
Output is correct |
14 |
Correct |
19 ms |
39764 KB |
Output is correct |
15 |
Correct |
18 ms |
39736 KB |
Output is correct |
16 |
Correct |
19 ms |
39724 KB |
Output is correct |
17 |
Correct |
22 ms |
39708 KB |
Output is correct |
18 |
Correct |
17 ms |
39728 KB |
Output is correct |
19 |
Correct |
17 ms |
39764 KB |
Output is correct |
20 |
Correct |
18 ms |
39724 KB |
Output is correct |
21 |
Correct |
19 ms |
39756 KB |
Output is correct |
22 |
Correct |
17 ms |
39816 KB |
Output is correct |
23 |
Correct |
18 ms |
39724 KB |
Output is correct |
24 |
Correct |
18 ms |
39764 KB |
Output is correct |
25 |
Correct |
17 ms |
39820 KB |
Output is correct |
26 |
Correct |
23 ms |
39740 KB |
Output is correct |
27 |
Correct |
17 ms |
39748 KB |
Output is correct |
28 |
Correct |
17 ms |
39756 KB |
Output is correct |
29 |
Correct |
20 ms |
39816 KB |
Output is correct |
30 |
Correct |
23 ms |
39784 KB |
Output is correct |
31 |
Correct |
17 ms |
39840 KB |
Output is correct |
32 |
Correct |
17 ms |
39752 KB |
Output is correct |
33 |
Correct |
17 ms |
39764 KB |
Output is correct |
34 |
Correct |
17 ms |
39736 KB |
Output is correct |
35 |
Correct |
17 ms |
39764 KB |
Output is correct |
36 |
Correct |
17 ms |
39788 KB |
Output is correct |
37 |
Correct |
17 ms |
39732 KB |
Output is correct |
38 |
Correct |
17 ms |
39764 KB |
Output is correct |
39 |
Correct |
17 ms |
39764 KB |
Output is correct |
40 |
Correct |
17 ms |
39816 KB |
Output is correct |
41 |
Correct |
16 ms |
39764 KB |
Output is correct |
42 |
Correct |
18 ms |
39816 KB |
Output is correct |
43 |
Correct |
18 ms |
39848 KB |
Output is correct |
44 |
Correct |
18 ms |
39824 KB |
Output is correct |
45 |
Correct |
21 ms |
39768 KB |
Output is correct |
46 |
Correct |
17 ms |
39764 KB |
Output is correct |
47 |
Correct |
19 ms |
39768 KB |
Output is correct |
48 |
Correct |
17 ms |
39764 KB |
Output is correct |
49 |
Correct |
18 ms |
39776 KB |
Output is correct |
50 |
Correct |
17 ms |
39764 KB |
Output is correct |
51 |
Correct |
18 ms |
39764 KB |
Output is correct |
52 |
Correct |
17 ms |
39756 KB |
Output is correct |
53 |
Correct |
17 ms |
39736 KB |
Output is correct |
54 |
Correct |
17 ms |
39752 KB |
Output is correct |
55 |
Correct |
17 ms |
39780 KB |
Output is correct |
56 |
Correct |
18 ms |
39836 KB |
Output is correct |
57 |
Correct |
16 ms |
39780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
39764 KB |
Output is correct |
2 |
Correct |
18 ms |
39728 KB |
Output is correct |
3 |
Correct |
17 ms |
39780 KB |
Output is correct |
4 |
Correct |
17 ms |
39764 KB |
Output is correct |
5 |
Correct |
16 ms |
39736 KB |
Output is correct |
6 |
Correct |
18 ms |
39824 KB |
Output is correct |
7 |
Correct |
18 ms |
39816 KB |
Output is correct |
8 |
Correct |
20 ms |
39828 KB |
Output is correct |
9 |
Correct |
17 ms |
39840 KB |
Output is correct |
10 |
Correct |
17 ms |
39728 KB |
Output is correct |
11 |
Correct |
17 ms |
39764 KB |
Output is correct |
12 |
Correct |
18 ms |
39764 KB |
Output is correct |
13 |
Correct |
19 ms |
39824 KB |
Output is correct |
14 |
Correct |
19 ms |
39764 KB |
Output is correct |
15 |
Correct |
18 ms |
39736 KB |
Output is correct |
16 |
Correct |
19 ms |
39724 KB |
Output is correct |
17 |
Correct |
22 ms |
39708 KB |
Output is correct |
18 |
Correct |
17 ms |
39728 KB |
Output is correct |
19 |
Correct |
17 ms |
39764 KB |
Output is correct |
20 |
Correct |
18 ms |
39724 KB |
Output is correct |
21 |
Correct |
19 ms |
39756 KB |
Output is correct |
22 |
Correct |
17 ms |
39816 KB |
Output is correct |
23 |
Correct |
18 ms |
39724 KB |
Output is correct |
24 |
Correct |
18 ms |
39764 KB |
Output is correct |
25 |
Correct |
17 ms |
39820 KB |
Output is correct |
26 |
Correct |
23 ms |
39740 KB |
Output is correct |
27 |
Correct |
17 ms |
39748 KB |
Output is correct |
28 |
Correct |
17 ms |
39756 KB |
Output is correct |
29 |
Correct |
20 ms |
39816 KB |
Output is correct |
30 |
Correct |
23 ms |
39784 KB |
Output is correct |
31 |
Correct |
17 ms |
39840 KB |
Output is correct |
32 |
Correct |
17 ms |
39752 KB |
Output is correct |
33 |
Correct |
17 ms |
39764 KB |
Output is correct |
34 |
Correct |
17 ms |
39736 KB |
Output is correct |
35 |
Correct |
17 ms |
39764 KB |
Output is correct |
36 |
Correct |
17 ms |
39788 KB |
Output is correct |
37 |
Correct |
17 ms |
39732 KB |
Output is correct |
38 |
Correct |
17 ms |
39764 KB |
Output is correct |
39 |
Correct |
17 ms |
39764 KB |
Output is correct |
40 |
Correct |
17 ms |
39816 KB |
Output is correct |
41 |
Correct |
16 ms |
39764 KB |
Output is correct |
42 |
Correct |
18 ms |
39816 KB |
Output is correct |
43 |
Correct |
18 ms |
39848 KB |
Output is correct |
44 |
Correct |
18 ms |
39824 KB |
Output is correct |
45 |
Correct |
21 ms |
39768 KB |
Output is correct |
46 |
Correct |
17 ms |
39764 KB |
Output is correct |
47 |
Correct |
19 ms |
39768 KB |
Output is correct |
48 |
Correct |
17 ms |
39764 KB |
Output is correct |
49 |
Correct |
18 ms |
39776 KB |
Output is correct |
50 |
Correct |
17 ms |
39764 KB |
Output is correct |
51 |
Correct |
18 ms |
39764 KB |
Output is correct |
52 |
Correct |
17 ms |
39756 KB |
Output is correct |
53 |
Correct |
17 ms |
39736 KB |
Output is correct |
54 |
Correct |
17 ms |
39752 KB |
Output is correct |
55 |
Correct |
17 ms |
39780 KB |
Output is correct |
56 |
Correct |
18 ms |
39836 KB |
Output is correct |
57 |
Correct |
16 ms |
39780 KB |
Output is correct |
58 |
Correct |
20 ms |
39936 KB |
Output is correct |
59 |
Correct |
21 ms |
40220 KB |
Output is correct |
60 |
Correct |
25 ms |
40284 KB |
Output is correct |
61 |
Correct |
59 ms |
40308 KB |
Output is correct |
62 |
Correct |
125 ms |
40904 KB |
Output is correct |
63 |
Correct |
28 ms |
40792 KB |
Output is correct |
64 |
Correct |
73 ms |
40832 KB |
Output is correct |
65 |
Correct |
21 ms |
39780 KB |
Output is correct |
66 |
Correct |
19 ms |
39804 KB |
Output is correct |
67 |
Correct |
17 ms |
39780 KB |
Output is correct |
68 |
Correct |
18 ms |
39800 KB |
Output is correct |
69 |
Correct |
20 ms |
39876 KB |
Output is correct |
70 |
Correct |
17 ms |
39844 KB |
Output is correct |
71 |
Correct |
32 ms |
39936 KB |
Output is correct |
72 |
Correct |
20 ms |
39868 KB |
Output is correct |
73 |
Correct |
21 ms |
39956 KB |
Output is correct |
74 |
Correct |
21 ms |
40240 KB |
Output is correct |
75 |
Correct |
30 ms |
40260 KB |
Output is correct |
76 |
Correct |
76 ms |
40292 KB |
Output is correct |
77 |
Correct |
162 ms |
40880 KB |
Output is correct |
78 |
Correct |
34 ms |
40804 KB |
Output is correct |
79 |
Correct |
90 ms |
40880 KB |
Output is correct |
80 |
Correct |
28 ms |
40796 KB |
Output is correct |
81 |
Correct |
38 ms |
40884 KB |
Output is correct |
82 |
Correct |
163 ms |
40892 KB |
Output is correct |
83 |
Correct |
16 ms |
39764 KB |
Output is correct |
84 |
Correct |
17 ms |
39764 KB |
Output is correct |
85 |
Correct |
29 ms |
39976 KB |
Output is correct |
86 |
Correct |
17 ms |
39892 KB |
Output is correct |
87 |
Correct |
19 ms |
39944 KB |
Output is correct |
88 |
Correct |
22 ms |
40308 KB |
Output is correct |
89 |
Correct |
24 ms |
40440 KB |
Output is correct |
90 |
Correct |
60 ms |
40412 KB |
Output is correct |
91 |
Correct |
145 ms |
41196 KB |
Output is correct |
92 |
Correct |
28 ms |
41164 KB |
Output is correct |
93 |
Correct |
79 ms |
41176 KB |
Output is correct |
94 |
Correct |
19 ms |
39892 KB |
Output is correct |
95 |
Correct |
32 ms |
39936 KB |
Output is correct |
96 |
Correct |
17 ms |
39852 KB |
Output is correct |
97 |
Correct |
17 ms |
39760 KB |
Output is correct |
98 |
Correct |
19 ms |
39740 KB |
Output is correct |
99 |
Correct |
17 ms |
39812 KB |
Output is correct |