CF105E.Lift and Throw

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a straight half-line divided into segments of unit length, which we will call positions. The positions are numbered by positive integers that start with 11 from the end of half-line, i. e. 11 , 22 , 33 and so on. The distance between the positions is the absolute difference between the respective numbers.

Laharl, Etna and Flonne occupy some positions on the half-line and they want to get to the position with the largest possible number. They are originally placed in different positions.

Each of the characters can perform each of the following actions no more than once:

  • Move a certain distance.
  • Grab another character and lift him above the head.
  • Throw the lifted character a certain distance.

Each character has a movement range parameter. They can only move to free positions, assuming that distance between those positions doesn't exceed the movement range.

One character can lift another character if the distance between the two characters equals 11 , and no one already holds that another character. We can assume that the lifted character moves to the same position as the person who has lifted him, and the position in which he stood before becomes free. A lifted character cannot perform any actions and the character that holds him cannot walk.

Also, each character has a throwing range parameter. It is the distance at which this character can throw the one lifted above his head. He can only throw a character to a free position, and only when there is a lifted character.

We accept the situation when one person grabs another one who in his turn has the third character in his hands. This forms a "column" of three characters. For example, Laharl can hold Etna while Etna holds Flonne. In this case, Etna and the Flonne cannot perform any actions, and Laharl can only throw Etna (together with Flonne) at some distance.

Laharl, Etna and Flonne perform actions in any order. They perform actions in turns, that is no two of them can do actions at the same time.

Determine the maximum number of position at least one of the characters can reach. That is, such maximal number xx so that one of the characters can reach position xx .

输入格式

The first line contains three integers: Laharl's position, his movement range and throwing range. The second and the third lines describe Etna's and Flonne's parameters correspondingly in the similar form. It is guaranteed that the three characters occupy distinct positions. All numbers in the input are between 11 and 1010 , inclusive.

输出格式

Print a single number — the maximum ordinal number of position which either Laharl, Etna or Flonne can reach.

输入输出样例

  • 输入#1

    9 3 3
    4 3 1
    2 3 3
    

    输出#1

    15

说明/提示

Let us explain how to reach position 1515 in the sample.

Initially Laharl occupies position 99 , Etna — position 44 and Flonne — position 22 .

First Laharl moves to position 66 .

Then Flonne moves to position 55 and grabs Etna.

Laharl grabs Flonne and throws to position 99 .

Flonne throws Etna to position 1212 .

Etna moves to position 1515 .

首页