Yoda: Use the Force. Yes. Now, the stone. Feel it. Concentrate!
Luke Skywalker is having exhausting practice at a God-forsaken planet Dagoba.
One of his main difficulties is navigating cumbersome objects using the Power.
Luke’s task is to hold several stones in the air simultaneously.
It takes complete concentration and attentiveness but the fellow keeps getting distracted.
Luke chose a certain order of stones and he lifts them, one by one, strictly following the order.
Each second Luke raises a stone in the air.
However, if he gets distracted during this second, he cannot lift the stone. Moreover, he drops some stones he had picked before.
The stones fall in the order that is reverse to the order they were raised.
They fall until the total weight of the fallen stones exceeds k kilograms or there are no more stones to fall down.
The task is considered complete at the moment when Luke gets all of the stones in the air.
Luke is good at divination and he can foresee all moments he will get distracted at.
Now he wants to understand how much time he is going to need to complete the exercise and move on.
Input
The first line contains three integers: n is the total number of stones, m is the number of moments when Luke gets distracted and k
(1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109).
Next n lines contain the stones’ weights wi (in kilograms) in the order Luke is going to raise them (1 ≤ wi ≤ 104).
Next m lines contain moments ti, when Luke gets distracted by some events (1 ≤ ti ≤ 109, ti < ti+1).
Output
Print a single integer — the number of seconds young Skywalker needs to complete the exercise.
Sample
input | output |
---|
5 1 4
1
2
3
4
5
4
| 8
|
Notes
In the first three seconds Luke raises stones that weight 1, 2 and 3 kilograms. On the fourth second he gets distracted and drops stones that weight 2 and 3 kilograms.
During the next four seconds he raises all the four stones off the ground and finishes the task.
Problem Author: Denis Dublennykh (prepared by Egor Shchelkonogov)