Horrible Restaurants

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

요약
식당 N곳에 별 0개부터 3개까지 부여할 때 드는 비용이 각각 주어질 때, 전체 별 개수가 k가 되도록 하는 최소 총비용을 k=1부터 3N까지 모두 구한다.
난이도

어려움10점 중 8점

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

문제

Ricardo is a restaurant critic, which means he spends his time eating at restaurants and giving them a rating. Each rating is an integer number of stars between 00 and 33, inclusive. Thus, there are exactly four possible ratings.

During his visit to Cheapland, he must review NN restaurants. Unfortunately, all of them are terrible, and if left to his honest opinion, Ricardo would give 00 stars to every restaurant. However, the government of Cheapland can bribe Ricardo to increase the rating of any restaurant.

Each restaurant has its own bribe costs, which depend both on the restaurant itself and on the number of stars awarded. Bribing Ricardo to give a restaurant 33 stars is always more expensive than bribing him for 22 stars, which in turn is more expensive than bribing him for 11 star. Naturally, no payment is required for a 00-star rating.

As one might imagine, the Cheapland government wants to spend as little as possible while making their gastronomic scene look as strong as possible. To plan their strategy, they need to determine the minimum cost required to achieve a total of kk stars among all the NN restaurants, for every integer value kk between 11 and 3N3N, inclusive.

However, since bribe costs vary from restaurant to restaurant, calculating these values isn’t straightforward – which is why they need your help.

입력

The first line contains an integer NN (1≤N≤2⋅1051 ≤ N ≤ 2 \cdot 10^5 ) indicating the number of restaurants.

Each of the next NN lines describes a restaurant with three integers C_1C\_1, C_2C\_2 and C_3C\_3 (1≤C_1<C_2<C_3≤1091 ≤ C\_1 < C\_2 < C\_3 ≤ 10^9 ), where C_iC\_i is the cost of getting a rating of ii stars for the restaurant.

출력

Output a line for each kk from 11 to 3N3N (inclusive), with an integer indicating the minimum total cost required to achieve exactly kk stars among all the NN restaurants.

예제2

  1. 예제 1

    입력
    3
    1 2 3
    2 10 11
    5 6 7
    
    예상 출력
    1
    2
    3
    5
    9
    10
    12
    20
    21
    
  2. 예제 2

    입력
    4
    999999998 999999999 1000000000
    999999998 999999999 1000000000
    999999998 999999999 1000000000
    999999998 999999999 1000000000
    
    예상 출력
    999999998
    999999999
    1000000000
    1999999998
    1999999999
    2000000000
    2999999998
    2999999999
    3000000000
    3999999998
    3999999999
    4000000000