Please do not give solution in image formate thanku. There were N students that decided to go on a camping trip. They found a suitable place for camping with a width of one meter and a length of 200 meters, knowing that their tents are 1 by 1 meter. They decided to build a rectangular fence and camp inside it. However every person i is satisfied if the sum of the two distances between his tent and the tent before and after him is atleast Xi(subscript) It is given that the first tent does not have a tent before it. So it's occupant is satisfied if the sum of the two distances between his tent and the tent after it and the fence before it is atleast Xi. Similarly the occupant of the last tent is satisfied if the sum of the distances between his tent and the tent before it and the fence after it is atleast Xi. Your task is to find the smallest possible perimeter for the fence. Input: The first line contains an Integer N denoting the number of elements in X. Each line i of the N subsequent lines contains an integer describing Xi Constraints: 1≤N≤20 0≤X[i]≤7 Sample input: 2 2 1 Output: 10 We put the first tent at co-ordinate 1 and the second at coordinate 4. So the length of the fence is 4 and the perimeter is 10. Sample input: 3 1 1 2 Output: 12 We put the first tent at coordinate 1 and the second at coordinate 5 and the third at coordinate 3 so that the length of the fence is 5 and the perimeter is 12. Sample Input: 4 0 1 2 3 Output: 16
Please do not give solution in image formate thanku.
There were N students that decided to go on a camping trip. They found a suitable place for camping with a width of one meter and a length of 200 meters, knowing that their tents are 1 by 1 meter.
They decided to build a rectangular fence and camp inside it. However every person i is satisfied if the sum of the two distances between his tent and the tent before and after him is atleast Xi(subscript)
It is given that the first tent does not have a tent before it. So it's occupant is satisfied if the sum of the two distances between his tent and the tent after it and the fence before it is atleast Xi. Similarly the occupant of the last tent is satisfied if the sum of the distances between his tent and the tent before it and the fence after it is atleast Xi.
Your task is to find the smallest possible perimeter for the fence.
Input:
The first line contains an Integer N denoting the number of elements in X.
Each line i of the N subsequent lines contains an integer describing Xi
Constraints:
1≤N≤20
0≤X[i]≤7
Sample input:
2
2
1
Output:
10
We put the first tent at co-ordinate 1 and the second at coordinate 4. So the length of the fence is 4 and the perimeter is 10.
Sample input:
3
1
1
2
Output:
12
We put the first tent at coordinate 1 and the second at coordinate 5 and the third at coordinate 3 so that the length of the fence is 5 and the perimeter is 12.
Sample Input:
4
0
1
2
3
Output:
16
Step by step
Solved in 4 steps with 3 images