405336: GYM101908 F Music Festival

Memory Limit:1024 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Music Festivaltime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard output

Music festivals should be fun, but some of them become so big that cause headache for the goers. The problem is that there are so many good attractions playing in so many stages that the simple task of choosing which shows to watch becomes too complex.

To help goers of such festivals, Fulano decided to create an app that, after evaluating the songs heard on the users' favorite streaming services, suggests which shows to watch so that there is no other combination of shows that is better according to the criteria described below:

  • To enjoy the experience as much as possible it is important to watch each of the selected shows from start to end;
  • Going to the festival and not seeing one of the stages is out of the question;
  • To ensure that the selection of artists is compatible with the user, the app counts how many songs from each artist the user had previously listened to on streaming services. The total number of known songs from chosen artists should be the largest possible.

Unfortunately the beta version of app received criticism, because users were able to think of better selections than those suggested. Your task in this problem is to help Fulano and write a program that, given the descriptions of the shows happening in each stage, calculates the ideal list of artists to the user.

The displacement time between the stages is ignored; therefore, as long as there is no intersection between the time ranges of any two chosen shows, it is considered that it is possible to watch both of them. In particular, if a show ends exactly when another one begins, you can watch both of them.

Input

The first line contains an integer $$$1 \leq N \leq 10$$$ representing the number of stages. The following $$$N$$$ lines describe the shows happening in each stage. The $$$i$$$-th of which consists of an integer $$$M_i \geq 1$$$, representing the number of shows scheduled for the $$$i$$$-th stage followed by $$$M_i$$$ show descriptions. Each show description contains 3 integers $$$i_j, f_j, o_j$$$ ($$$1 \leq i_j < f_j \leq 86400$$$; $$$1 \leq o_j \leq 1000$$$), representing respectively the start and end time of the show and the number of songs of the singer performing that were previously heard by the user. The sum of the $$$M_i$$$ shall not exceed 1000.

Output

Your program must produce a single line with an integer representing the total number of songs previously heard from the chosen artist, or −1 if there is no valid solution.

ExamplesInput
3
4 1 10 100 20 30 90 40 50 95 80 100 90
1 40 50 13
2 9 29 231 30 40 525
Output
859
Input
3
2 13 17 99 18 19 99
2 13 14 99 15 20 99
2 13 15 99 18 20 99
Output
-1

加入题单

算法标签: