A1355 | [COCI-2016_2017-contest5]#5 Tuna
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Fisherman Šime caught N tunas last night. With the help of a special app, he offerred them for sale to a famous Japanese company that specializes in purchasing quality fish. In what way does the app estimate the value, or the price, of a tuna?
Based on the photo of the tuna, the app returns two estimated values, P1 and P
2. If the difference between the estimates is less than or equal to X, then the higher value is taken. If the difference is strictly larger than X, the app returns a third estimate P3 and then that estimate is taken as the final value of the tuna.
Write a programme that will, based on the given estimates (sometimes two, sometimes three of them) for each of N tunas, output the total value of caught tunas.
Based on the photo of the tuna, the app returns two estimated values, P1 and P
2. If the difference between the estimates is less than or equal to X, then the higher value is taken. If the difference is strictly larger than X, the app returns a third estimate P3 and then that estimate is taken as the final value of the tuna.
Write a programme that will, based on the given estimates (sometimes two, sometimes three of them) for each of N tunas, output the total value of caught tunas.
输入格式
The first line of input contains the integer N (1 ≤ N ≤ 20), the number of tunas from the task.
The second line of input contains the integer X (1 ≤ X ≤ 10), the number from the task.
Then, N blocks follow in one of the two following forms:
● In one line, two integers P1 and P2 (1 ≤ P1, P2 ≤ 100) from the task,
or ● In one line, two integers P1 and P2(1 ≤ P1, P2 ≤ 100) from the task, and in the second line integer P3 (1 ≤ P3 ≤ 100) from the task.
The second line of input contains the integer X (1 ≤ X ≤ 10), the number from the task.
Then, N blocks follow in one of the two following forms:
● In one line, two integers P1 and P2 (1 ≤ P1, P2 ≤ 100) from the task,
or ● In one line, two integers P1 and P2(1 ≤ P1, P2 ≤ 100) from the task, and in the second line integer P3 (1 ≤ P3 ≤ 100) from the task.
输出格式
The first and only line of output must contain the total value of caught tunas.
输入输出样例
输入 #1
5 2 3 4 2 1 5 3 4 4 4 2
输出 #1
19
输入 #2
4 2 3 5 2 8 4 6 5 6 3 7
输出 #2
22
输入 #3
3 10 20 50 30 20 40 50 70 20 10
输出 #3
90
Clarification of the second test case:
Šime caught 4 tunas. For the first tuna, the app returned two estimates (3 and 5). Since the difference
between these two estimates is less than or equal to 2, the value of the first tuna is 5. For the second
tuna, the difference between the first two estimates (2 and 8) is higher than 2, so the app returned a third
estimate, 4. The third tuna’s value is 6 (6 – 5 ≤ 2), and the value of the fourth tuna is taken as the third
estimate, 7, because the difference between the given estimates (6 and 3) is higher than 2.
Šime caught 4 tunas. For the first tuna, the app returned two estimates (3 and 5). Since the difference
between these two estimates is less than or equal to 2, the value of the first tuna is 5. For the second
tuna, the difference between the first two estimates (2 and 8) is higher than 2, so the app returned a third
estimate, 4. The third tuna’s value is 6 (6 – 5 ≤ 2), and the value of the fourth tuna is taken as the third
estimate, 7, because the difference between the given estimates (6 and 3) is higher than 2.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted