#801. 魔法珠子T4
魔法珠子T4
No submission language available for this problem.
题目描述
在一条数轴上散落着个魔法珠,第个魔法珠位于,且能量值为,属性为。魔法珠可以提供不同的魔法,只有不超过7种的属性,按照属性从1-7编号。
现在蜗牛老师希望从左往右依次选取恰好个魔法珠,因为魔法的相互影响,在选取魔法珠的过程中,选取的相邻的魔法珠属性不能相同。
现在问,满足以上要求的情况下,选取个魔法珠的能量值总和为多大?
输入格式
第一行两个整数,表示魔法珠总数和要挑选的魔法珠总数
接下来行,每行三个整数.
输出格式
一行一个整数,表示能获得的能量的最大值,如果不能合法的选出个,输出。
样例数据
input
5 2
-1 1 1
0 2 3
1 3 3
-2 5 3
4 5 5
output
10
选取在-2,4的两个魔法珠,能量总和为5+5=10
input
2 2
-1 2 2
-3 2 2
output
-1
由于n==m,所有魔法珠都得选,但两个魔法珠属性值相同,无法都选,故没有合法方案,答案为-1.
input
10 4
-1 5 6
0 5 5
8 6 7
3 5 5
2 1 5
12 2 5
6 10 2
-7 10 1
-9 3 2
-2 5 1
output
31
数据规模与约定

对于 数据保证 , ,, , 所有 互不相同。
时间限制:
空间限制:
Background
Special for beginners, ^_^
Description
Given two integers x and y, print the sum.
Format
Input
Two integers x and y, satisfying .
Output
One integer, the sum of x and y.
Samples
123 500
623
Limitation
1s, 1024KiB for each test case.