##### Canadian Computing Competition: 2019 Stage 1, Senior #4

You are planning a trip to visit tourist attractions. The attractions are numbered from to and must be visited in this order. You can visit at most attractions per day, and want to plan the trip to take the fewest number of days as possible.

Under these constraints, you want to find a schedule that has a nice balance between the attractions visited each day. To be precise, we assign a score to attraction . Given a schedule, each day is given a score equal to the maximum score of all attractions visited that day. Finally, the scores of each day are summed to give the total score of the schedule. What is the maximum possible total score of the schedule, using the fewest days possible?

#### Input Specification

The first line contains two space-separated integers and .

The next line contains space separated integers .

For 3 of the 15 available marks, .

For an additional 3 of the 15 available marks, and .

**An additional subtask worth 15 marks has been added to break solutions that are incorrect but AC on the official test data. Data provided by ** .

#### Output Specification

Output a single integer, the maximum possible total score.

#### Sample Input

```
5 3
2 5 7 1 4
```

#### Sample Output

`12`

#### Explanation of Output for Sample Input

We need to have at least two days to visit all the attractions, since we cannot visit all attractions in one day.

Visiting the first two attractions on day 1 will give a score of 5, and visiting the last three attractions on day 2 will give a score of 7, for a total score of 12.

Visiting three attractions on day 1, and two attractions on day 2, which is the only possibility to visit in the fewest number of days possible, would yield a total score of .

## Comments

Hi, I was thinking of using F[k][j] where it will tell you the highest score you could get in k days with j breaks along the way (where each break is when you could go on further that day but you could didn't, for example, you could go 4 but you only took 1 that day so that adds 3 breaks). To update the table I was thinking of using an RMQ. The complexity of this should be O(2*(N+K)), not taking into account the RMQ, while using a little trick updating the table. Now I am stuck on the dumbest thing I can't find a way of doing an RMQ with potentially a million terms (maybe a sparse table? but I think that takes up too much space and maybe time)). SOOOO now I am just thinking my entire method is wrong, any hints? please.

Hi, I've managed to get the first 6 points with a solution of complexity O(N*K) but I don't really see how I can get the last 9 points. Can someone help? How to O(N) it does not seem possible.

This comment is hidden due to too much negative feedback. Click here to view it.

Are you trolling or what?

dp?

Can an editorial be written for this problem?

Please

can i get a hint for the last 9 marks?

This comment is hidden due to too much negative feedback. Click here to view it.

Is this question sovlable with python? I see nobody got AC for this one, similar with senior Q5.

Yes, this question is solvable using python.

So far, all Python ACs are in PyPy. No CPython ACs yet. https://dmoj.ca/problem/ccc19s4/submissions/?status=AC&language=PY2&language=PY3&language=PYPY&language=PYPY3

Edit: Yeah it's possible, but only after wasting time on it. https://dmoj.ca/submission/3436645Use Pypy 2 or 3

criesPoor boy who decided to skip S3 and focus on S4 :( I feel you.