Crazy Fencing


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
Python

Problem Description

A fence consists of N planks arranged and joined together in a row.

The planks are numbered from 1 to N from left to right.

The bottom of each plank is horizontal, and the two sides are vertical, but the top may be slanted at an angle (meaning the two sides are not the same height), as shown in the figure below.

The adjacent sides of any two neighboring planks have the same height. (Refer to the sample illustration.)

Given the length of each side and the width (bottom length) of each plank, please calculate the total area of all the planks.

Input Format

  • The first line contains the integer N.
  • The second line contains N+1 integers h1, h2, …, hN+1. The height of the left side of the i-th plank is hi, and the height of the right side is hi+1.
  • The third line contains N integers w1, w2, …, wN. Here, wi represents the width of the i-th plank.

Output Format

Output the total area of all the planks, rounded to one decimal place.

Constraints

  • 1 ≤ N ≤ 10000
  • 1 ≤ hi ≤ 100
  • 1 ≤ wi ≤ 100

Examples

Sample Input 1
3
2 3 6 2
4 1 1
Sample Output 1
18.5

Explanation: The fence is shown as follows:

The areas of the three planks from left to right are:
4⋅(2+3)/2 = 10,
1⋅(3+6)/2 = 4.5,
1⋅(6+2)/2 = 4,
Total area = 18.5.

Sample Input 2
4
6 4 9 7 3
5 2 4 1
Sample Output 2
75.0

Explanation: The fence is shown as follows:

The areas of the four planks from left to right are: 25, 13, 32, 5,
Total area = 75.0 (Note: Keep one decimal place).


Comments

There are no comments at the moment.