QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#7317. 矩形内的矩形

Statistics

Bobo 有一个大矩形,其左下角和右上角的坐标分别为 $(0, 0)$ 和 $(w, 10^6)$。他还有 $n$ 个位于大矩形内部的小轴对齐矩形。第 $i$ 个矩形的权重为 $v_i$。对于每个小矩形,其左边界或右边界(但不能同时)与大矩形的左侧或右侧重合。

Bobo 想要选择一个小矩形的子集,使得这些矩形可以相互接触,但不能重叠(即不存在属于多于一个矩形内部的点)。在所有可能的选择中,他希望找到权重之和最大的方案。

输入格式

输入包含零个或多个测试用例,并以文件结束符(EOF)终止。对于每个测试用例:

第一行包含两个整数 $n$ 和 $w$ ($1 \le n \le 2000, 2 \le w \le 10^6$),分别表示小矩形的数量和大矩形的宽度。

接下来的 $n$ 行中,第 $i$ 行包含五个整数 $type_i, l_i, a_i, b_i$ 和 $v_i$ ($type_i \in \{0, 1\}, 0 \le a_i < b_i \le 10^6, 1 \le l_i < w, 0 \le v_i \le 10^6$),其中 $v_i$ 是第 $i$ 个矩形的权重。这里,$type_i = 0$ 表示第 $i$ 个矩形的左下角和右上角坐标分别为 $(0, a_i)$ 和 $(l_i, b_i)$;而 $type_i = 1$ 表示第 $i$ 个矩形的左下角和右上角坐标分别为 $(w - l_i, a_i)$ 和 $(w, b_i)$。

保证对于所有 $1 \le i < j \le n$,满足 $a_i \neq a_j, a_i \neq b_j, b_i \neq a_j$ 以及 $b_i \neq b_j$。此外,所有 $n$ 的总和不超过 $2000$。

输出格式

对于每个测试用例,输出一个整数,表示权重之和的最大值。

样例

输入格式 1

3 10
0 3 1 6 12
0 3 3 4 100
1 9 2 5 11
3 10
0 3 1 6 12
0 1 3 4 5
1 9 2 5 11
6 5
1 1 17 32 4
0 3 1 18 7
1 3 4 8 12
1 2 15 20 14
1 1 30 33 16
1 4 2 16 13

输出格式 1

100
16
42

说明

对于第三个测试用例,Bobo 可以选择第 3、第 4 和第 5 个矩形。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.