Integers Shop solution codeforces
The integers shop sells nn segments. The iith of them contains all integers from lili to riri and costs cici coins.
Tomorrow Vasya will go to this shop and will buy some segments there. He will get all integers that appear in at least one of bought segments. The total cost of the purchase is the sum of costs of all segments in it.
After shopping, Vasya will get some more integers as a gift. He will get integer xx as a gift if and only if all of the following conditions are satisfied: Integers Shop solution codeforces
 Vasya hasn’t bought xx.
 Vasya has bought integer ll that is less than xx.
 Vasya has bought integer rr that is greater than xx.
Vasya can get integer xx as a gift only once so he won’t have the same integers after receiving a gift.
For example, if Vasya buys segment [2,4][2,4] for 2020 coins and segment [7,8][7,8] for 2222 coins, he spends 4242 coins and receives integers 2,3,4,7,82,3,4,7,8 from these segments. He also gets integers 55 and 66 as a gift.
Due to the technical issues only the first ss segments (that is, segments [l1,r1],[l2,r2],…,[ls,rs][l1,r1],[l2,r2],…,[ls,rs]) will be available tomorrow in the shop.
Vasya wants to get (to buy or to get as a gift) as many integers as possible. If he can do this in differents ways, he selects the cheapest of them.
For each ss from 11 to nn, find how many coins will Vasya spend if only the first ss segments will be available.
The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
The first line of each test case contains the single integer nn (1≤n≤1051≤n≤105) — the number of segments in the shop.
Each of next nn lines contains three integers lili, riri, cici (1≤li≤ri≤109,1≤ci≤1091≤li≤ri≤109,1≤ci≤109) — the ends of the iith segments and its cost.
It is guaranteed that the total sum of nn over all test cases doesn’t exceed 2⋅1052⋅105.
For each test case output nn integers: the ssth (1≤s≤n1≤s≤n) of them should be the number of coins Vasia will spend in the shop if only the first ss segments will be available.
3 2 2 4 20 7 8 22 2 5 11 42 5 11 42 6 1 4 4 5 8 9 7 8 7 2 10 252 1 11 271 1 10 1
20 42 42 42 4 13 11 256 271 271
In the first test case if s=1s=1 then Vasya can buy only the segment [2,4][2,4] for 2020 coins and get 33 integers.
The way to get 77 integers for 4242 coins in case s=2s=2 is described in the statement.
In the second test case note, that there can be the same segments in the shop.

For Solution
Click Here!