Split the Picture

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

요약
각 세로 절단 위치마다 가로 절단을 골라 네 사분면 합의 최댓값과 최솟값 차이를 최소로 만든다.
난이도

어려움10점 중 9점

유형
누적 합, 정렬, 분할 정복, 이분 탐색
정답자
아직 제출이 없습니다

문제

Nicolae broke up with his girlfriend, Cristina, and now he wants to forget all the pictures he has with her. Out of those pictures, there is one very special picture that has nn special pixels at integer coordinates. To each of these pixels, Nicolae assigned an integer value that describes the amount of sadness he feels when looking at it.

Frustrated, Nicolae wants to cut the picture into 4 parts. To do that, he will choose a point P=(x+0.5,y+0.5)P = (x + 0.5, y + 0.5) such that xx and yy are integers. Then he will cut the picture alongside the lines parallel to coordinate axes that cross the point PP.

Nicolae calls the resulting 4 parts AA, BB, CC, and DD. For a part XX, he defines S(X)S(X), the total sadness of the part, as the sum of the sadness values of the special pixels inside the part.

It would take Nicolae exactly max⁡(S(A),S(B),S(C),S(D))−min⁡(S(A),S(B),S(C),S(D))\max(S(A), S(B), S(C), S(D)) - \min(S(A), S(B), S(C), S(D)) days of sadness until he forgets the picture, so choosing the point PP optimally could spare him a lot of pain.

For each x∈1,2,…,n−1x \in \\{1, 2, \ldots, n - 1\\}, Nicolae asks himself what would be the minimum number of sad days until he forgets the picture if he were to choose the point PP on the vertical line with coordinate x+0.5x + 0.5.

입력

The first input line contains the number nn (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5).

Each of the next nn lines contains three integers x_ix\_i, y_iy\_i, s_is\_i (1≤x_i,y_i≤n1 \leq x\_i, y\_i \leq n and 1≤s_i≤1091 \leq s\_i \leq 10^{9}) representing the coordinates and the sadness value for each special pixel of the picture. Some pixels may coincide.

출력

The output should contain n−1n - 1 integers: for each x∈1,2,…,n−1x \in \\{1, 2, \ldots, n - 1\\}, print the minimum number of sad days until Nicolae forgets the picture if he were to choose the point PP on the vertical line with coordinate x+0.5x + 0.5.

예제1

  1. 예제 1

    입력
    4
    4 4 2
    3 2 4
    1 3 3
    2 2 5
    
    예상 출력
    9
    3
    9