Tomatoes
Time limit1sMemory limit1024 MB
Given a row of n tomatoes with three initially ripe, count how many are ripe after d days of spreading to adjacent tomatoes.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
There are tomatoes in a long row, numbered from to . Three of them, numbers , , and , are already ripe when the simulation starts on day . Every day, each unripe tomato that is directly next to a ripe tomato ripens. After day , the neighbors of the first three ripe tomatoes have ripened. After day , the neighbors of the tomatoes that ripened on day have also ripened, and so on.
Write a program that, given , , and the numbers , , and , computes how many tomatoes are ripe after days.
Input
The first line contains two integers () and ().
The second line contains , , and . They are all different and lie in the range .
Output
Print a single integer: the number of ripe tomatoes after days.