CCO '25 P6 - Shopping Deals

View as PDF

Submit solution


Points: 35 (partial)
Time limit: 5.0s
Memory limit: 256M

Author:
Problem type
Canadian Computing Olympiad: 2025 Day 2, Problem 3

You are shopping from a store that sells a total of M items. The store layout can be modelled as a two-dimensional plane, where the i-th item is located at the point (x_i,y_i) and has a price of p_i.

The store offers N shopping deals. The i-th shopping deal is specified by a point (a_i,b_i), and for a cost of c_i, you can obtain one of every item within exactly one of the following four regions of your choice:

  • The region of points (x,y) such that x \le a_i and y \le b_i.

  • The region of points (x,y) such that x \le a_i and y \ge b_i.

  • The region of points (x,y) such that x \ge a_i and y \le b_i.

  • The region of points (x,y) such that x \ge a_i and y \ge b_i.

Each shopping deal can only be used at most once. Items can also be purchased individually by paying their respective price p_i.

You want to obtain at least one of each item in the store. Find the minimum total cost you must pay to do so.

Input Specification

The first line of input contains two space-separated integers N and M.

The next N lines of input each contain three space-separated integers, a_i, b_i, and c_i (-10^9 \le a_i,b_i \le 10^9, 1 \le c_i \le 10^9).

The next M lines of input each contain three space-separated integers, x_i, y_i, and p_i (-10^9 \le x_i,y_i \le 10^9, 1 \le p_i \le 10^9).

The following table shows how the available 25 marks are distributed:

Marks Awarded Bounds on N Bounds on M Additional Constraints
1 mark 1 \le N \le 8 1 \le M \le 20 None
3 marks 1 \le N \le 70 1 \le M \le 20 None
3 marks 1 \le N \le 70 1 \le M \le 70 None
4 marks 1 \le N \le 100 1 \le M \le 100\,000 No two points (a_i,b_i) or (x_j,y_j) have the same x or y-coordinate.
2 marks 1 \le N \le 100 1 \le M \le 100\,000 None
8 marks 1 \le N \le 1\,000 1 \le M \le 100\,000 No two points (a_i,b_i) or (x_j,y_j) have the same x or y-coordinate.
4 marks 1 \le N \le 1\,000 1 \le M \le 100\,000 None

Output Specification

On a single line, output the minimum total cost that you must pay to obtain at least one of each item.

Sample Input

2 4
1 1 3
3 3 13
0 0 2
0 2 5
2 0 4
2 2 3

Sample Output

 12

Explanation for Sample Output

Use the first shopping deal on the region \{(x,y) \mid x \le 1, y \ge 1\} to obtain the second item. Then, purchase items 1, 3, and 4 individually. The total cost is 3+(2+4+3) = 12.


Comments

There are no comments at the moment.