Shock Wave

시간 제한2초메모리 제한2048 MB

요약
일렬로 놓인 타일에 필요한 파워가 주어지고, 타일 x를 한 번 치면 모든 타일 i에 |i-x|만큼 파워가 더해질 때, 모든 타일을 부수는 데 필요한 최소 펀치 수를 구한다.
난이도

어려움10점 중 8점

유형
수학, 그리디, 배열
정답자
아직 제출이 없습니다

문제

Bessie is experimenting with a powerful hoof implant that has the ability to create massive shock waves. She has NN (2≤N≤1052 \leq N \leq 10^5) tiles lined up in front of her, which require powers of at least p_0,p_1,…,p_N−1p\_0,p\_1,\dots,p\_{N-1} to break, respectively (0≤p_i≤10180 \leq p\_i \leq 10^{18}).

Bessie can apply power by punching a specific tile but due to the strange nature of her implant, it will not apply any power to the tile she punches. Instead, if she chooses to punch tile xx once, where xx is an integer in \[0,N−1]\[0,N-1], it applies ∣i−x∣|i-x| power to tile ii for all integers ii in the range \[0,N−1]\[0,N-1]. This power is also cumulative, so applying 22 power twice to a tile will apply a total of 44 power to the tile.

Please determine the fewest number of punches required to break all the tiles.

입력

The first line contains TT (1≤T≤1001 \leq T \leq 100) representing the number of test cases.

Line 2t2t contains a single integer NN, the number of tiles in test case tt.

Line 2t+12t+1 contains NN space separated numbers p_0,p_1,…,p_N−1p\_0,p\_1, \ldots, p\_{N-1} representing that tile ii takes p_ip\_i power to be broken.

It is guaranteed that the sum of all NN in a single input does not exceed 5⋅1055\cdot 10^5.

출력

TT lines, the iith line representing the answer to the iith test case.

예제1

  1. 예제 1

    입력
    6
    5
    0 2 4 5 8
    5
    6 5 4 5 6
    5
    1 1 1 1 1
    5
    12 10 8 6 4
    7
    6 1 2 3 5 8 13
    2
    1000000000000000000 1000000000000000000
    
    예상 출력
    2
    3
    2
    4
    4
    2000000000000000000