Given tasks with weekday, start and end times, and point values, pick a non-overlapping set that maximizes total points, and report the per-day breakdown.
Medium5Dynamic programmingSortingIntervalsGreedyInterviewNo attempts yetTime limit2sMemory limit512 MBThe well-known and feared hacker SideBarCoder has finally decided to turn himself in to the authorities after years of making life hell for system administrators. SideBarCoder never caused any damage directly, but he drove administrators furious and became famous for leaving humorous notes in files on systems that were supposedly impenetrable.
SideBarCoder accepted an offer that a large company made publicly: a very good salary, on the condition that he reveal his true identity and from then on work on improving the security of the Linux system. However, the Federal Police was not as lenient as SideBarCoder had hoped and arrested him on his first day of work.
Fortunately, the judge in charge of the case took into account that SideBarCoder had never caused damage to any company, and ruled that he could shorten his time in jail by doing volunteer work at the schools in his neighborhood (such as painting classroom walls, helping to look after babies at daycare centers, and so on).
The judge gave SideBarCoder a list of possible tasks. Each task is worth a certain number of points that can be used to reduce the sentence. SideBarCoder must carry out the tasks within one week, from Monday to Friday. For each task, the judge specified the day, the start and end time, and the number of points. The points of a task depend on its difficulty, not on its duration. So looking after a class of twenty children for two hours is worth more points than painting a classroom, which takes four hours.
Naturally, SideBarCoder thought of using a computer to work out how to get as many points as possible. However, as an additional penalty, the judge ruled that SideBarCoder may not go near a computer until he has served his sentence. In despair, SideBarCoder asked you to write a program that determines which tasks he should choose.
To have its points counted, a task must be done in full, that is, from the start to the end of its period without interruption. The set of tasks selected by your program must not contain conflicting tasks. Two tasks conflict if both are on the same day and their time intervals intersect. Since all the tasks take place in the neighborhood where SideBarCoder lives, travel time between tasks is ignored. So he can perform two tasks A and B without conflict when the end time of A equals the start time of B.
The input contains several test cases. The first line of a test case contains an integer N (0≤N≤10000), the number of tasks offered by the judge. Each of the next N lines describes one task in the following format:
Codigo Pontos Dia Inicio Final
where
Codigo is an integer that uniquely identifies the task (1≤ Codigo ≤10000);Pontos is an integer giving the number of points of the task (1≤ Pontos ≤50);Dia is a three-character string giving the weekday of the task: Seg (Monday), Ter (Tuesday), Qua (Wednesday), Qui (Thursday), or Sex (Friday);Inicio and Final are the start and end time of the task in HH:MM format (between 00:00 and 23:59). A one-digit hour may be written with one digit, as in 8:00. The end of a task is always after its start, and a task lies entirely within one day.The end of the input is indicated by N=0.
For each test case, print six lines. The first line contains the text Total de pontos:, followed by one space, followed by an integer: the maximum number of points SideBarCoder can collect. The next five lines give the points to be earned on each weekday from Monday to Friday, in the format shown below.
Total de pontos: 21
Seg: 10
Ter: 0
Qua: 11
Qui: 0
Sex: 0
The points for a day are the maximum number of points obtainable from that day's tasks alone, and the five values add up to the number on the first line.