A. Tricky Alchemy

Codeforces
IDCF912A
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a **yellow** ball one needs two yellow crystals, **green** — one yellow and one blue, and for a **blue** ball, three blue crystals are enough. Right now there are _A_ yellow and _B_ blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls. ## Input The first line features two integers _A_ and _B_ (0 ≤ _A_, _B_ ≤ 109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers _x_, _y_ and _z_ (0 ≤ _x_, _y_, _z_ ≤ 109) — the respective amounts of yellow, green and blue balls to be obtained. ## Output Print a single integer — the minimum number of crystals that Grisha should acquire in addition. [samples] ## Note In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
在冬季假期,圣诞球的需求异常高涨。由于现在已经 #cf_span[2018],炼金术的进步使得利用魔法晶体能够高效且简便地制造球体。 格里沙需要获取一些黄色、绿色和蓝色的球。已知制造一个 *黄色* 球需要两个黄色晶体,*绿色* 球需要一个黄色和一个蓝色晶体,而制造一个 *蓝色* 球则只需三个蓝色晶体。 目前格里沙手中有 #cf_span[A] 个黄色晶体和 #cf_span[B] 个蓝色晶体。请计算他需要额外获取多少晶体,才能制造出所需数量的球。 第一行包含两个整数 #cf_span[A] 和 #cf_span[B](#cf_span[0 ≤ A, B ≤ 109]),分别表示格里沙手中黄色和蓝色晶体的数量。 第二行包含三个整数 #cf_span[x]、#cf_span[y] 和 #cf_span[z](#cf_span[0 ≤ x, y, z ≤ 109]),分别表示需要制造的黄色、绿色和蓝色球的数量。 请输出一个整数——格里沙需要额外获取的最少晶体数量。 在第一个测试用例中,格里沙需要五个黄色晶体和四个蓝色晶体来制造两个黄色球、一个绿色球和一个蓝色球。为此,他需要再获取两个晶体:一个黄色和一个蓝色。 ## Input 第一行包含两个整数 #cf_span[A] 和 #cf_span[B](#cf_span[0 ≤ A, B ≤ 109]),分别表示格里沙手中黄色和蓝色晶体的数量。第二行包含三个整数 #cf_span[x]、#cf_span[y] 和 #cf_span[z](#cf_span[0 ≤ x, y, z ≤ 109]),分别表示需要制造的黄色、绿色和蓝色球的数量。 ## Output 请输出一个整数——格里沙需要额外获取的最少晶体数量。 [samples] ## Note 在第一个测试用例中,格里沙需要五个黄色晶体和四个蓝色晶体来制造两个黄色球、一个绿色球和一个蓝色球。为此,他需要再获取两个晶体:一个黄色和一个蓝色。
**Definitions** Let $ A, B \in \mathbb{Z}_{\geq 0} $ be the initial number of yellow and blue crystals. Let $ x, y, z \in \mathbb{Z}_{\geq 0} $ be the required numbers of yellow, green, and blue balls. **Constraints** $ 0 \leq A, B \leq 10^9 $ $ 0 \leq x, y, z \leq 10^9 $ **Resource Requirements** To produce: - $ x $ yellow balls: $ 2x $ yellow crystals - $ y $ green balls: $ y $ yellow and $ y $ blue crystals - $ z $ blue balls: $ 3z $ blue crystals Total required: - Yellow crystals: $ 2x + y $ - Blue crystals: $ y + 3z $ **Objective** Compute the minimum additional crystals needed: $$ \max(0, 2x + y - A) + \max(0, y + 3z - B) $$
Samples
Input #1
4 3
2 1 1
Output #1
2
Input #2
3 9
1 1 3
Output #2
1
Input #3
12345678 87654321
43043751 1000000000 53798715
Output #3
2147483648
API Response (JSON)
{
  "problem": {
    "name": "A. Tricky Alchemy",
    "description": {
      "content": "During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF912A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.\n\n...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "在冬季假期,圣诞球的需求异常高涨。由于现在已经 #cf_span[2018],炼金术的进步使得利用魔法晶体能够高效且简便地制造球体。\n\n格里沙需要获取一些黄色、绿色和蓝色的球。已知制造一个 *黄色* 球需要两个黄色晶体,*绿色* 球需要一个黄色和一个蓝色晶体,而制造一个 *蓝色* 球则只需三个蓝色晶体。\n\n目前格里沙手中有 #cf_span[A] 个黄色晶体和 #cf_span[B] 个蓝色晶体。...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ A, B \\in \\mathbb{Z}_{\\geq 0} $ be the initial number of yellow and blue crystals.  \nLet $ x, y, z \\in \\mathbb{Z}_{\\geq 0} $ be the required numbers of yellow, green, and blue b...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments