Delete operation - MarisaOJ: Marisa Online Judge

Delete operation

Time limit: 1000 ms
Memory limit: 256 MB
Given an array $A$ of $n$ integers. You can perform the following operation at most $k$ times: - Pick 2 indices $l, r$ such that $1 \le l \le r \le n$, assign $0$ to each element $A_l, A_{l + 1}, ...,A_r$. Find the maximum possible sum of elements in $A$ after performing some operations? ### Input - The first line contains 2 integers $n, k$. - The second line contains $n$ integers $A_i$. ### Output - Print the maximum possible sum of $A$. ### Constraints - $1 \le n, k \le 5000$. - $|A_i| \le 10^9$. ### Example Input: ``` 4 1 1 -3 1 -10 ``` Output: ``` 1 ```