P29699 [洛谷] [COCI2016-2017#5] TUNA
普及-
题目描述

Problem Description

A fisherman caught $N$ tuna fish last night and plans to sell them to a platform.

For each fish, the platform provides two estimated values $P_1$ and $P_2$. If the difference between these two values does not exceed $X$, the higher value is taken as the fish's value. Otherwise, if the difference exceeds $X$, another value $P_3$ is used.

Given the values (which may be two or three) for $N$ fish, calculate the total value of all the fish.

Input Format

The first line contains an integer $N$, representing the number of tuna fish.

The second line contains an integer $X$.

The following lines are divided into $N$ parts to describe the information for each fish. Each part is formatted as one of the following:

  • This part contains only one line with two integers $P_1$ and $P_2$.
  • This part contains two lines: the first line has two integers $P_1$ and $P_2$, and the second line has one integer $P_3$.

Output Format

Output the total value of all the fish.

Sample Input and Output

Sample Input #1

5
2
3 4
2 1
5 3
4 4
4 2

Sample Output #1

19

Sample Input #2

4
2
3 5
2 8
4
6 5
6 3
7

Sample Output #2

22

Sample Input #3

3
10
20 50
30
20 40
50
70 20
10

Sample Output #3

90

Notes

[Sample 2 Explanation]

The fisherman caught $4$ tuna fish, and the value of $X$ is $2$:

Fish Number $p_1$ $p_2$ $p_3$ Difference Final Value
$1$ $3$ $5$ / $2 \le 2$ $5$
$2$ $2$ $8$ $4$ $6 \gt 2$ $4$
$3$ $6$ $5$ / $1 \le 2$ $6$
$4$ $6$ $3$ $7$ $3 \le 7$ $7$

Thus, the total value is $5 + 4 + 6 + 7 = 22$.

[Data Range and Constraints]

For $100\%$ of the data, $1 \le N \le 20$, $1 \le X \le 10$, $1 \le P_1, P_2, P_3 \le 100$.

[Source and Credits]

This problem is translated from COCI 2016-2017 CONTEST #5 T1 Tuna.

This problem is scored according to the original COCI settings, with a maximum score of $50$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 2 3 4 2 1 5 3 4 4 4 2
样例输出
19