Under construction

Still being built. Things may change

Doing Assignments Efficiently

Interview

Time limit1sMemory limit1024 MB

Summary
Pick a subset of assignments to do shortest-first, maximizing points (half for late work within 24 hours), then report the least total time that achieves that maximum.
Level

Medium5 of 10

Topics
Dynamic programming, Sorting
Solved
No attempts yet

Problem

Kim Hanyang is exhausted from the backlog of assignments, even during exam period. He already did badly on the midterm, and he does not want to retake the course, so he wants to finish the assignments quickly and study for the final exam.

To avoid a retake, more points from assignments are better. Studying for the final takes a lot of time, so less time spent on assignments is also better. Kim Hanyang cares more about the total points of the assignments than the total time they take. So, when he gets the most points, doing the assignments in order of shortest time is the most efficient plan for him. If he can get the most points, he is fine with skipping some assignments.

To make this plan, Kim Hanyang lined up all the assignments in a row. For each ii-th assignment AiA_i, he recorded in a table the time TiT_i (hours) needed to finish it, the time DiD_i (hours) left from now until the deadline, and the points PiP_i.

If he starts assignment AiA_i now, he gets the following points.

  1. If he finishes within DiD_i hours, he gets the full PiP_i points.
  2. If he finishes after DiD_i but within Di+24D_i+24 hours, it is a late submission, so he gets ⌊Pi/2⌋\lfloor P_i / 2\rfloor points.
  3. If he finishes after Di+24D_i+24 hours, he gets 0 points.

He is focused enough that each assignment takes exactly TiT_i hours, but not focused enough to work on two assignments at once.

Input

The first line contains the number of assignments NN (1≤N≤201 \le N \le 20). The next NN lines each contain three positive integers: the time TiT_i (1≤Ti≤1031 \le T_i \le 10^3), the time left DiD_i (1≤Di≤N×1031 \le D_i \le N \times 10^3), and the points PiP_i (1≤Pi≤1061 \le P_i \le 10^6) for the ii-th assignment. All values are separated by spaces.

Output

Print the maximum points Kim Hanyang can get by following the efficient plan, and the minimum time (hours) it takes to get those points, separated by a space.

Examples3

  1. Example 1

    Input
    4
    6 48 10
    18 24 5
    12 24 5
    30 24 10
    
    Expected output
    20 48
    
  2. Example 2

    Input
    3
    120 120 15
    30 60 5
    30 60 10
    
    Expected output
    15 60
    
  3. Example 3

    Input
    2
    100 10 100
    200 20 200
    
    Expected output
    0 0