Ice Cream Queue
All submissions for this problem are available.### Read problem statements in [Hindi](http://www.codechef.com/download/translated/LTIME76/hindi/ICECREM.pdf), [Bengali](http://www.codechef.com/download/translated/LTIME76/bengali/ICECREM.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/LTIME76/mandarin/ICECREM.pdf), [Russian](http://www.codechef.com/download/translated/LTIME76/russian/ICECREM.pdf), and [Vietnamese](http://www.codechef.com/download/translated/LTIME76/vietnamese/ICECREM.pdf) as well. There are $N$ people standing in a queue for Chef's ice cream. They are numbered $1$ through $N$ from the front to the back of the queue. Chef's customers do not like to wait too long. For each valid $i$, we know that the ice cream ordered by the $i$-th person will take $P_i$ seconds to prepare and cost $V_i$ units of money, but if this person has to wait strictly more than $W_i$ seconds in the queue (until Chef starts preparing their order), they will leave. At any time, it is only allowed to prepare the ice cream of the person standing at the front of the queue. Chef wants to maximise his profit (the sum of prices of sold ice creams). In order to do that, he may choose to kick some of the customers (possibly nobody) out of the queue. Find the maximum profit Chef can make. ### Input - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - $N$ lines follow. For each $i$ ($1 \le i \le N$), each of these lines contains three space-separated integers $W_i$, $P_i$ and $V_i$. ### Output For each test case, print a single line containing one integer — the maximum possible profit. ### Constraints - $1 \le T \le 10$ - $1 \le N \le 40$ - $1 \le P_i, W_i, V_i \le 10^9$ for each valid $i$ ### Subtasks **Subtask #1 (50 points):** $1 \le N \le 20$ **Subtask #2 (50 points):** original constraints ### Example Input ``` 2 2 3 7 4 7 10 5 2 3 7 4 6 10 5 ``` ### Example Output ``` 9 5 ```
|Tags||deadwing97, kingofnumbers, ltime76|
|Time Limit:||4 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.