CF1608E.The Cells on the Paper
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
On an endless checkered sheet of paper, n cells are chosen and colored in three colors, where n is divisible by 3 . It turns out that there are exactly 3n marked cells of each of three colors!
Find the largest such k that it's possible to choose 3k cells of each color, remove all other marked cells, and then select three rectangles with sides parallel to the grid lines so that the following conditions hold:
- No two rectangles can intersect (but they can share a part of the boundary). In other words, the area of intersection of any two of these rectangles must be 0 .
- The i -th rectangle contains all the chosen cells of the i -th color and no chosen cells of other colors, for i=1,2,3 .
输入格式
The first line of the input contains a single integer n — the number of the marked cells ( 3≤n≤105 , n is divisible by 3).
The i -th of the following n lines contains three integers xi , yi , ci ( ∣xi∣,∣yi∣≤109 ; 1≤ci≤3 ), where (xi,yi) are the coordinates of the i -th marked cell and ci is its color.
It's guaranteed that all cells (xi,yi) in the input are distinct, and that there are exactly 3n cells of each color.
输出格式
Output a single integer k — the largest number of cells you can leave.
输入输出样例
输入#1
9 2 3 1 4 1 2 2 1 3 3 4 1 5 3 2 4 4 3 2 4 1 5 2 2 3 5 3
输出#1
6
输入#2
3 1 1 1 2 2 2 3 3 3
输出#2
3
说明/提示
In the first sample, it's possible to leave 6 cells with indexes 1,5,6,7,8,9 .
In the second sample, it's possible to leave 3 cells with indexes 1,2,3 .