| ICPC Thailand National Competition 2024 |
|---|
| Закончено |
A company is in the process of designing a groundbreaking new game and has decided to hold several executive meetings to kick off the project.
Over the next $$$t$$$ days, the company needs to schedule $$$n$$$ executives to attend these meetings. On any given day, $$$i$$$, the company requires at least $$$a_i$$$ executives to be present.
Each executive's "satisfaction" is determined by the length of their longest continuous break from attending meetings. For instance, if an executive attends meetings on days $$$1$$$, $$$5$$$, and $$$7$$$ during a $$$7$$$-day period, their satisfaction value would be 3, representing the break they get from day $$$2$$$ to day $$$4$$$. If an executive does not attend any meetings during the entire period, their satisfaction value would be $$$t$$$.
You have been tasked by the CEO of the company to determine the maximum total satisfaction of all executives.
The first line contains two integers $$$n,t$$$ $$$(1 \le n,t \le 2,000,000)$$$ denoting the number of executives in total and the number of days of meetings.
The second line contains $$$t$$$ integers $$$a_1, a_2,...,a_t$$$ $$$(0 \le a_i \le n)$$$ — the minimum number of executives required on the $$$i$$$-th day.
Output the maximum sum of satisfaction of all the executives.
3 70 1 1 3 2 0 1
9
10 106 1 2 5 5 0 7 3 4 2
54
In the first example, one way to arrange the meeting is as follows:
| Название |
|---|


