A. Compote

Codeforces
IDCF746A
Time1000ms
Memory256MB
Difficulty
implementationmath
English · Original
Chinese · Translation
Formal · Original
Nikolay has _a_ lemons, _b_ apples and _c_ pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits. Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. ## Input The first line contains the positive integer _a_ (1 ≤ _a_ ≤ 1000) — the number of lemons Nikolay has. The second line contains the positive integer _b_ (1 ≤ _b_ ≤ 1000) — the number of apples Nikolay has. The third line contains the positive integer _c_ (1 ≤ _c_ ≤ 1000) — the number of pears Nikolay has. ## Output Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. [samples] ## Note In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
Nikolay 有 #cf_span[a] 个柠檬、#cf_span[b] 个苹果和 #cf_span[c] 个梨。他决定煮一锅果酱。根据食谱,水果的比例应为 #cf_span[1: 2: 4]。这意味着果酱中每有一个柠檬,就必须恰好有 #cf_span[2] 个苹果和 #cf_span[4] 个梨。你不能将这些水果捣碎、掰开或切片。这些水果——柠檬、苹果和梨——必须以完整的形式放入果酱中。 你的任务是确定 Nikolay 可以用来煮果酱的柠檬、苹果和梨的最大总数。如果 Nikolay 无法使用任何水果,则请输出 #cf_span[0]。 第一行包含一个正整数 #cf_span[a](#cf_span[1 ≤ a ≤ 1000])——Nikolay 拥有的柠檬数量。 第二行包含一个正整数 #cf_span[b](#cf_span[1 ≤ b ≤ 1000])——Nikolay 拥有的苹果数量。 第三行包含一个正整数 #cf_span[c](#cf_span[1 ≤ c ≤ 1000])——Nikolay 拥有的梨的数量。 请输出 Nikolay 可以用来煮果酱的柠檬、苹果和梨的最大总数。 在第一个测试用例中,Nikolay 可以使用 #cf_span[1] 个柠檬、#cf_span[2] 个苹果和 #cf_span[4] 个梨,因此答案是 #cf_span[1 + 2 + 4 = 7]。 在第二个测试用例中,Nikolay 可以使用 #cf_span[3] 个柠檬、#cf_span[6] 个苹果和 #cf_span[12] 个梨,因此答案是 #cf_span[3 + 6 + 12 = 21]。 在第三个测试用例中,Nikolay 没有足够的梨来煮任何果酱,因此答案是 #cf_span[0]。 ## Input 第一行包含一个正整数 #cf_span[a](#cf_span[1 ≤ a ≤ 1000])——Nikolay 拥有的柠檬数量。第二行包含一个正整数 #cf_span[b](#cf_span[1 ≤ b ≤ 1000])——Nikolay 拥有的苹果数量。第三行包含一个正整数 #cf_span[c](#cf_span[1 ≤ c ≤ 1000])——Nikolay 拥有的梨的数量。 ## Output 请输出 Nikolay 可以用来煮果酱的柠檬、苹果和梨的最大总数。 [samples] ## Note 在第一个测试用例中,Nikolay 可以使用 #cf_span[1] 个柠檬、#cf_span[2] 个苹果和 #cf_span[4] 个梨,因此答案是 #cf_span[1 + 2 + 4 = 7]。在第二个测试用例中,Nikolay 可以使用 #cf_span[3] 个柠檬、#cf_span[6] 个苹果和 #cf_span[12] 个梨,因此答案是 #cf_span[3 + 6 + 12 = 21]。在第三个测试用例中,Nikolay 没有足够的梨来煮任何果酱,因此答案是 #cf_span[0]。
Let $ a $, $ b $, and $ c $ be the number of lemons, apples, and pears respectively. The compote requires fruits in the ratio $ 1 : 2 : 4 $, meaning for every $ x $ lemons, we need $ 2x $ apples and $ 4x $ pears, where $ x \in \mathbb{Z}_{\geq 0} $. The constraints are: - $ x \leq a $ - $ 2x \leq b $ - $ 4x \leq c $ The maximum possible value of $ x $ is: $$ x_{\text{max}} = \min\left( a, \left\lfloor \frac{b}{2} \right\rfloor, \left\lfloor \frac{c}{4} \right\rfloor \right) $$ The total number of fruits used is: $$ x_{\text{max}} + 2x_{\text{max}} + 4x_{\text{max}} = 7x_{\text{max}} $$ Thus, the maximum total number of fruits is: $$ \boxed{7 \cdot \min\left( a, \left\lfloor \frac{b}{2} \right\rfloor, \left\lfloor \frac{c}{4} \right\rfloor \right)} $$
Samples
Input #1
2
5
7
Output #1
7
Input #2
4
7
13
Output #2
21
Input #3
2
3
2
Output #3
0
API Response (JSON)
{
  "problem": {
    "name": "A. Compote",
    "description": {
      "content": "Nikolay has _a_ lemons, _b_ apples and _c_ pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF746A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Nikolay has _a_ lemons, _b_ apples and _c_ pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Nikolay 有 #cf_span[a] 个柠檬、#cf_span[b] 个苹果和 #cf_span[c] 个梨。他决定煮一锅果酱。根据食谱,水果的比例应为 #cf_span[1: 2: 4]。这意味着果酱中每有一个柠檬,就必须恰好有 #cf_span[2] 个苹果和 #cf_span[4] 个梨。你不能将这些水果捣碎、掰开或切片。这些水果——柠檬、苹果和梨——必须以完整的形式放入果酱中。\n\n你...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ a $, $ b $, and $ c $ be the number of lemons, apples, and pears respectively.\n\nThe compote requires fruits in the ratio $ 1 : 2 : 4 $, meaning for every $ x $ lemons, we need $ 2x $ apples and ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments