Pile of batteries
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Regardless of whether there will be power outages this year or not — batteries will always come in handy. So Marichka and Zenyk went looking for them. They were very lucky, because a battery sale was currently taking place in the store.
There are \(n\) batteries in the store’s warehouse. Each of them has a width of 2 and a height of 1. Platforms of width 1 are placed on the warehouse floor one after another in a row, such that the first platform has coordinate 1, the second — 2, and so on. It is known that each battery was placed one by one from above vertically downwards until it touched the platform or another battery. The \(i\)-th battery was lowered such that it was above platforms \(x_i\) and \(x_i+1\).
According to the sale conditions, Zenyk and Marichka could choose one platform and lift it upwards. If there are any other batteries above the battery being lifted — the platform will lift them as well. All batteries lifted by the platform can be bought at a discount.
Zenyk and Marichka have already chosen the platform they will lift, \(p\).
Help the store clerks calculate the number of batteries that Zenyk and Marichka will buy.
Input
The first line contains a single integer \(n\) — the number of batteries.
The second line contains \(n\) integers \(x_i\) — the coordinates of the platforms on which the respective batteries are placed.
The third line contains a single integer \(p\) — the coordinate of the platform that Zenyk and Marichka will lift.
Output
Print a single integer — the number of batteries that the platform chosen by Zenyk and Marichka will lift.
Constraints
\(1 \le n \le 10^5\),
\(1 \le x_i \le 10^5\),
\(1 \le p \le 10^5\).
The problem evaluation consists of the following subtasks:
1 point — the first example from the statement,
24 points — a block of tests in which \(1 \le n \le 10\) and \(1 \le x_i, p \le 10\),
25 points — a block of tests in which \(11 \le n \le 100\) and \(1 \le x_i, p \le 1000\),
50 points — a block of tests in which \(101 \le n \le 10^5\) and \(1 \le x_i, p \le 10^5\).
You will receive points for a subtask only if you give the correct answer to all tests in that subtask.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 9 6 1 2 3 5 1 4 6 3 5 | 4 |
Notes
As seen in the figure — Marichka and Zenyk chose the fifth platform. It will rise by one unit, without touching the first battery. After that, it will start lifting the fifth one, and in turn, the fifth one will lift the eighth. After one more unit of height, the fifth battery will start lifting the seventh, and the seventh — the ninth.
In total, the platform will lift four different batteries.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|