Tuna
Time limit1sMemory limit64 MB
For each tuna, take the larger of two estimates when they differ by at most X, otherwise take a third estimate, and print the sum.
- Level
Easy1 of 10
- Topics
- Implementation, Math
- Solved
- No attempts yet
Problem
Fisherman Šime caught tunas last night. Using a special app, he offered them for sale to a well-known Japanese company that buys quality fish. How does the app estimate the value, or price, of a tuna?
From a photo of the tuna, the app returns two estimates, and . If the difference between the estimates is less than or equal to , the higher estimate is taken. If the difference is strictly greater than , the app returns a third estimate , and that estimate is taken as the final value of the tuna.
Given the estimates for each of the tunas (sometimes two of them, sometimes three), write a program that outputs the total value of the caught tunas.
Input
The first line contains the integer (), the number of tunas.
The second line contains the integer () described above.
Then blocks follow, one per tuna, each in one of these two forms:
- One line with two integers and ().
- One line with two integers and (), followed by a second line with the integer ().
The second form is used when the difference between and is greater than .
Output
Output the total value of the caught tunas on a single line.