You are participating in a scavenger hunt in a city with
Constraints
Building
Subtask 1 [4/15]
A building will contain at most
Subtask 2 [4/15]
Subtask 3 [7/15]
No additional constraints.
Input Specification
The first line contains
The next line contains
The next line contains
The
The next
Output Specification
Output one integer, the minimum time it takes to obtain all
Sample Input 1
4 4 3
9 10 10
1 1 1
3
4
2
1 2 3
2 3 5
2 4 4
3 4 10
Sample Output 1
20
Explanation for Sample Output 1
This sample case satisfies the condition of subtask
The optimal way to obtain all items is:
- Create item
yourself. - Go from building
to building . - Go from building
to building . Collect item here. - Go from building
to building . Collect item here.
In total, you take
Sample Input 2
5 6 2
1000000000 1000000000
1 2
3
4 5
1 2 1
1 3 4
2 3 2
2 4 1
3 5 6
5 4 2
Sample Output 2
6
Explanation for Sample Output 2
This sample case satisfies the condition of subtask
The optimal way to obtain all items is:
- Go from building
to building . - Go from building
to building . Collect item here. - Go from building
to building . - Go from building
to building . Collect item here.
In total, you take
Sample Input 3
4 6 3
3 3 5
2 3 1
2 3
2 3 4
3
1 2 4
1 3 10
2 3 6
1 4 2
2 4 3
3 4 8
Sample Output 3
9
Explanation for Sample Output 3
The optimal way to obtain all items is:
- Go from building
to building . Collect item and here. - Create item
yourself.
In total, you take
Comments
If this questions let you collect items not in order, it will be a 12 or 15 points question