아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Histogram Fencing

면접 대비

시간 제한1초메모리 제한1024 MB

요약
히스토그램 모양으로 생긴 땅의 각 기둥 너비와 높이가 주어질 때, 땅 전체의 둘레를 계산한다.
난이도

보통10점 중 4점

유형
구현, 배열, 수학, 기하
정답자
아직 제출이 없습니다

문제

Your next-door neighbor has asked to borrow some fencing to put around all of his land. Being the kind neighbor that you are, you’ve decided to lend him your fencing. But being the stingy farmer that you are, you’ve also decided to give him exactly enough, and no more. An interesting quality of your neighbor’s farm is that it’s shaped like a histogram. Given the width and height of each column of the histogram, determine the perimeter of your neighbor’s land.

입력

The first line will contain a single integer n that indicates the number of data sets that follow. Each data set will start with a single integer x denoting the number of ‘bars’ in your neighbor’s histogram shaped plot of land. The next two lines consists of x space separated integers each, representing the widths and heights respectively of each bar of land.

출력

For each test case, output the amount of fencing needed to surround the perimeter of your neighbors histogram shaped plot of land.

예제1

  1. 예제 1

    입력
    2
    7
    1 1 1 1 1 1 1
    1 3 6 3 3 3 2
    3
    1 2 3
    1 2 3
    
    예상 출력
    26
    18