Adelaide in a Day
Everyone knows Adelaide is a cool place to live, and now it's your chance to prove it!
Today, of your friends have flown in from out of state. You want to take everyone around the city, doing Adelaide's most fun activities!
Well, you'd like to at least. As CS students, your friends have wacky schedules, and are only available to join the tour during specific time windows. The activities you want to do also run over specific time windows, and you can't be two places at once!
Each activity has a fun value. If one of your friends fully participate in an activity with fun value , then your tour earns
credibility. If
friends participate in an activity with fun
, then your tour earns
credibility.
How can you select the activities you do, to maximise your credibility?
Input
The first line consists of an integer
, the number of friends you have.
The next lines contain
and
., indicating that your
th friend will join your tour at the start of time
and leave at the end of time
.
The next line consists of an integer
, the number of activities you can do with your friends today.
The next lines contain
,
, and
, indicating that the
th activity runs from the start of time
to the end of time
and has
fun.
Output
Output the maximum "credibility" your tour can gain: the product of each activity's fun with the number of people who attend.
Clarifications
- Your friends join/leave your tour instantly.
- If a friend leaves halfway through an activity, your tour does not gain the credibility from that.
- If a friend joins the activity the exact time it starts, and leaves the exact time it ends, your tour will gain credibility.
Example
Input 1
3
1 5
3 6
5 7
5
1 2 3
1 5 4
3 4 3
4 7 5
6 7 2
Output 1
11
We pick activities (
1 2 3
), (
3 4 3
) and (
6 7 2
) for our schedule.
- Friend
joins at
. You are now with
friend.
- Do activity
until
. This activity has
fun, so you get
credibility for each friend you are with. (
in total).
- Friend
joins at
. You are now with
friends.
- Do activity
until
. This activity has
fun, so you get
credibility for each friend you are with. (
in total).
- Friend
leaves at
. At the same time, friend
joins. You are still with
friends.
- Friend
leaves at
. You are now with
friend.
- Do activity
until
. This activity has
fun, so you get
credibility for each friend you are with. (
in total). Friend
also leaves at
.
Overall, your tour gains credibility, which is the maximum possible.
Input 2
9
6 7
1 10
4 10
1 4
2 10
3 5
2 5
5 7
3 5
5
3 5 5
5 5 20
1 2 10
4 6 5
2 5 10
Output 2
160
We take activities and
.
friends attend activity
, and
friends attend activity
.
Input 3
3
1 5
1 4
2 5
6
1 1 1
2 2 1
3 3 1
4 4 1
5 5 1
1 5 10
Output 3
13
We take activities through
.
Comments