#abc217h. H - Snuketoon
H - Snuketoon
Score : points
问题描述
在由AtCoder, Inc.开发的一款名为Snuketoon的游戏中,玩家扮演Snuke,需要躲避水枪喷出的水。
游戏平台是一个无限数轴,游戏开始时,Snuke位于点处。
从游戏开始起,Snuke每秒钟可以从以下三种移动中选择一种执行:向负方向移动1单位,向正方向移动1单位,或者保持原地不动。更形式化地表示,如果在游戏开始后秒(,其中为整数)时,Snuke的位置为,那么他在秒时的位置可以是、或。
Snuke会因被水枪淋湿而受到伤害。水枪共射击次,第次射击用、和表示如下:
- 在游戏开始后秒时,水枪从左边或右边发射水柱。假设此时Snuke的位置为,若他在以下范围内,则受到如下伤害:
- 当时,若他在范围内,则受到点伤害。
- 当时,若他在范围内,则受到点伤害。
职业游戏玩家高桥想要最小化在第次射击结束后Snuke受到的总伤害,以便在游戏中发推文。请计算当游戏以最小化伤害的方式进行时,Snuke所受到的总伤害。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
In a game called Snuketoon, developed by AtCoder, Inc., the player plays as Snuke to dodge water from water guns.
The platform consists of an infinite number line, and Snuke is at the point at the beginning of the game.
Starting from the beginning of the game, Snuke can make one of the three moves in each second: move in the negative direction, move in the positive direction, or remain still. More formally, if Snuke's position is at seconds (, is an integer) from the beginning of the game, his position at seconds can be , , or .
Snuke takes damage from getting soaked by water guns. The water guns shoot times, and the -th shot is represented by , , and as follows.
- At seconds from the beginning of the game, water is shot from the left or right. Let be Snuke's position at that time. He takes the following damage if he is in the following range.
- When , he takes points of damage if he is in the range .
- When , he takes points of damage if he is in the range .
Takahashi, a pro gamer, wants to minimize the total damage taken by Snuke after the end of the -th shot, to post a tweet on this game. Find the total damage taken by Snuke when the game is played to minimize it.
Constraints
- is or .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the number of points of damage taken by Snuke when the game is played to minimize it.
Sample Input 1
3
1 0 3
3 1 0
4 0 6
Sample Output 1
7
For convenience, let denote the number of seconds elapsed from the beginning of the game. The optimal course of movements for Snuke until all the shots are done is as follows.
- When , Snuke is at the point . He moves in the positive direction.
- When , Snuke is at the point and takes points of damage from the first shot. He moves in the negative direction.
- When , Snuke is at the point . He remains still.
- When , Snuke is at the point and takes no damage from the second shot. He moves in the positive direction.
- When , Snuke is at the point and takes points of damage from the third shot.
Here, Snuke takes a total of points of damage, so you should print .
Sample Input 2
3
1 0 1
6 1 1
8 0 -1
Sample Output 2
0
Sample Input 3
5
1 0 1000000000
2 1 -1000000000
3 0 1000000000
4 1 -1000000000
5 0 1000000000
Sample Output 3
4999999997
update @ 2024/3/10 09:38:10