Logo
(追記) (追記ここまで)

7872번 - Cave 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB38171341.935%

문제

As an owner of a land with a cave you were delighted when you last heard that underground fuel tanks are great business. Of course, the more volume one can store, the better. In case of your cave, the effective volume is not easy to calculate, because the cave has a rather sophisticated shape (see figure). Thank heavens it is degenerate in one dimension!

The cave. All ponds that can be flooded with fuel are marked black.

Furthermore, there is some electrical wiring on the ceiling of the cave. You can never be sure if the insulation is intact, so you want to keep the fuel level just below the ceiling at every point. You can pump the fuel to whatever spots in the cave you choose, possibly creating several ponds. Bear in mind though that the fuel is a liquid, so it minimises its gravitational energy, e.g., it will run evenly in every direction on a flat horizontal surface, pour down whenever possible, obey the rule of communicating vessels, etc. As the cave is degenerate and you can make the space between the fuel level and the ceiling arbitrarily small, you actually want to calculate the maximum possible area of ponds that satisfy aforementioned rules.

입력

The input contains several test cases. The first line of the input contains a positive integer Z ≤ 15, denoting the number of test cases. Then Z test cases follow,.

In the first line of an input instance, there is an integer n (1 ≤ n ≤ 106) denoting the width of the cave. The second line of input consists of n integers p1, p2, . . . , pn and the third line consists of n integers s1, s2, . . . , sn, separated by single spaces. The numbers pi and si satisfy 0 ≤ pi < si ≤ 1000 and denote the floor and ceiling level at interval [i, i + 1), respectively.

출력

Your program is to print out one integer: the maximum total area of admissible ponds in the cave.

제한

예제 입력 1

1
15
6 6 7 5 5 5 5 5 5 1 1 3 3 2 2
10 10 10 11 6 8 7 10 10 7 6 4 7 11 11

예제 출력 1

14

힌트

출처

ICPC > Regionals > Europe > Central European Regional Contest > CERC 2009 C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /