Codeforces Round 995 (Div. 3) |
---|
Finished |
Suppose you play a game where the game field looks like a strip of $$$1 \times 10^9$$$ square cells, numbered from $$$1$$$ to $$$10^9$$$.
You have $$$n$$$ snakes (numbered from $$$1$$$ to $$$n$$$) you need to place into some cells. Initially, each snake occupies exactly one cell, and you can't place more than one snake into one cell. After that, the game starts.
The game lasts for $$$q$$$ seconds. There are two types of events that may happen each second:
Each second, exactly one of the events happens.
If at any moment of time, any snake runs into some obstacle (either another snake or the end of the strip), you lose. Otherwise, you win with the score equal to the maximum cell occupied by any snake so far.
What is the minimum possible score you can achieve?
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n \le 20$$$; $$$1 \le q \le 2 \cdot 10^5$$$) — the number of snakes and the number of events. Next $$$q$$$ lines contain the description of events — one per line.
The $$$i$$$-th line contains
Additional constraint on the input: the given sequence of events is valid, i. e. a snake of length $$$1$$$ never shrinks.
Print one integer — the minimum possible score.
3 61 +1 -3 +3 -2 +2 -
4
5 135 +3 +5 -2 +4 +3 +5 +5 -2 +3 -3 +3 -2 +
11
In the first test, the optimal strategy is to place the second snake at cell $$$1$$$, the third snake — at $$$2$$$, and the first one — at $$$3$$$. The maximum occupied cell is cell $$$4$$$, and it's the minimum possible score.
In the second test, one of the optimal strategies is to place:
Name |
---|