Parklife

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

요약
호 위에 서로 교차하지 않는 다리가 주어질 때, 각 호 구간에서 보이는 다리가 k개 이하가 되도록 고른 부분집합의 최대 미적 가치 합을 모든 k에 대해 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 그리디, 정렬, 구간
정답자
아직 제출이 없습니다

문제

Figure 1. Gapcheon and an Expo bridge in a cloudy day

Gapcheon is a stream that flows through the Daedeok Innopolis: A research district in Daejeon which includes KAIST, Expo Science Park, National Science Museum, among many others. The waterfront of Gapcheon is used as a park, which is a facility for leisure and recreation. 

In this problem, we model the Gapcheon as a slightly curved arc. In the arc, there are exactly 10610^6 points marked by each centimeter. In Gapcheon, there are NN bridges that connect two distinct points in the arc in a straight line segment. Such a line segment may touch other segments in an endpoint but never crosses them otherwise. For each pair of points, there exists at most one bridge that directly connects those two points.

Figure 2. x,y,zx, y, z are bridges that do not cross but only touch each other in an endpoint. This can be a possible input instance. Points with number 8…1068 \ldots 10^6 are omitted for brevity.


Figure 3. x,yx, y are bridges that cross each other. This is not a possible input instance. Points with number 8…1068 \ldots 10^6 are omitted for brevity.

The city council is planning to place some lights in the bridges, to make Gapcheon as a more enjoyable place in the night. For each bridge, the city council calculated the aesthetical value if the lights are installed in these bridges. These value can be represented as a positive integer. 

However, too many lightings will annoy the residents at midnight. To address this issue, the council decided to make some regulations: for every arc between two adjacent points, there should be at most kk lighted bridges visible from there. We call a line segment visible from an arc connecting i,i+1i, i+1, when one endpoint of the segment has an index at most ii, and another endpoint of the segment has an index at least i+1i+1.

The city council wants to consider the tradeoff between light pollution and the night view, so you should provide the maximum possible sum of aesthetical value, for all integers 1≤k≤N1 \le k \le N.

입력

The first line contains an integer NN. (1≤N≤250,0001 \le N \le 250\\,000)

The next NN lines contain three integers S_i,E_i,V_iS\_i, E\_i, V\_i, which denotes there is a straight line bridge connecting points S_i,E_iS\_i, E\_i, and having aesthetic value V_iV\_i. (1≤S_i<E_i≤106,1≤V_i≤1091 \le S\_i < E\_i \le 10^6, 1 \le V\_i \le 10^9).

It's guaranteed that no lines connect the same pair of points, and no two different line segments cross.

출력

Print NN integers separated by a space. The ii-th integer (1≤i≤N1 \le i \le N) should be the answer if k=ik = i.

힌트

Figure 4. Depiction of Sample Input 1.

 

Copyright notice for Figure 1:사진제공(한국관광공사 김지호)-한국관광공사\

예제2

  1. 예제 1

    입력
    6
    1 2 10
    2 3 10
    1 3 21
    3 4 10
    4 5 10
    3 5 19
    
    예상 출력
    41 80 80 80 80 80
    
  2. 예제 2

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