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

10284번 - Lift Problems 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB111474046.512%

문제

On the ground floor (floor zero) of a large university building a number of students are waiting for a lift. Normally, the lift stops at every floor where one or more students need to get out, but that is annoying for the students who want to get out on a higher floor. Alternatively, the lift could skip some floors, but that is annoying for the students who wanted to get out on one of those floors.

Specifically, a student will be annoyed on every floor where the lift stops, if the lift has not yet reached the floor on which he or she wants to get out. If the lift skips the floor on which a student wants to get out, he or she will be annoyed on that floor and every higher floor, up to (and excluding) the floor where the lift makes its next stop and the student can finally get out to start walking back down the stairs to his or her destination.

For example, if a student wants to get out on the fifth floor, while the lift stops at the second, seventh and tenth floor, the student will be annoyed on floors two, five and six. In total, this student will thus be annoyed on three floors.

Upon entering the lift, every student presses the button corresponding to the floor he or she wants to go to, even if it was already pressed by someone else. The CPU controlling the lift thus gets to know exactly how many students want to get out on every floor.

You are charged with programming the CPU to decide on which floors to stop. The goal is to minimize the total amount of lift anger: that is, the number of floors on which every student is annoyed, added together for all students.

You may ignore all the people who may (want to) enter the lift at any higher floor. The lift has to operate in such a way that every student waiting at the ground floor can reach the floor she or he wants to go to by either getting out at that floor or by walking down the stairs.

입력

On the first line one positive number: the number of test cases, at most 100. After that per test case:

  • one line with a single integer n (1 ≤ n ≤ 1 500): the number of floors of the building, excluding the ground floor.
  • one line with n space-separated integers si (0 ≤ si ≤ 1 500): for each floor i, the number of students si that want to get out.

출력

Per test case:

  • one line with a single integer: the smallest possible total amount of lift anger.

제한

예제 입력 1

3
5
0 3 0 0 7
5
0 0 3 0 7
10
3 1 4 1 5 9 2 6 5 3

예제 출력 1

7
6
67

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2014 Preliminaries D번

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

출처

대학교 대회

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

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