A. Vladik and Courtesy

Codeforces
IDCF811A
Time2000ms
Memory256MB
Difficulty
brute forceimplementation
English · Original
Chinese · Translation
Formal · Original
At regular competition Vladik and Valera won _a_ and _b_ candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they **don’t consider as their own**. You need to know, who is the first who can’t give the right amount of candy. ## Input Single line of input data contains two space-separated integers _a_, _b_ (1 ≤ _a_, _b_ ≤ 109) — number of Vladik and Valera candies respectively. ## Output Pring a single line "_Vladik_’’ in case, if Vladik first who can’t give right amount of candy, or "_Valera_’’ otherwise. [samples] ## Note Illustration for first test case: ![image](https://espresso.codeforces.com/8f52167c388373a2219c4bfde3dbb114b6bb78a8.png) Illustration for second test case: ![image](https://espresso.codeforces.com/28f89ddea145bced9efb935e74751fe615d2b6d7.png)
在常规比赛中,Vladik 和 Valera 分别赢得了 #cf_span[a] 和 #cf_span[b] 颗糖果。Vladik 向 Valera 赠送了 #cf_span[1] 颗糖果。之后,Valera 为了不让别人觉得他不够慷慨,回赠了 Vladik #cf_span[2] 颗糖果。接着,Vladik 为了同样的原因,在下一轮赠送了 #cf_span[3] 颗糖果给 Valera。 更形式化地说,两人轮流赠送对方比上一轮收到的多一颗的糖果。 这个过程持续到其中一人无法送出规定数量的糖果为止。两人从对方那里收到的糖果 *不被视为他们自己的*。你需要知道,谁是第一个无法送出正确数量糖果的人。 输入数据仅有一行,包含两个用空格分隔的整数 #cf_span[a], #cf_span[b] (#cf_span[1 ≤ a, b ≤ 109]),分别表示 Vladik 和 Valera 拥有的糖果数量。 如果 Vladik 是第一个无法送出正确数量糖果的人,请输出一行 "_Vladik_",否则输出 "_Valera_"。 第一个测试用例的图示: 第二个测试用例的图示: ## Input 输入数据仅有一行,包含两个用空格分隔的整数 #cf_span[a], #cf_span[b] (#cf_span[1 ≤ a, b ≤ 109]),分别表示 Vladik 和 Valera 拥有的糖果数量。 ## Output 如果 Vladik 是第一个无法送出正确数量糖果的人,请输出一行 "_Vladik_",否则输出 "_Valera_"。 [samples] ## Note 第一个测试用例的图示: 第二个测试用例的图示:
Let $ a $ be the initial number of candies Vladik has, and $ b $ be the initial number of candies Valera has. The exchange proceeds in turns, starting with Vladik: - Turn 1 (Vladik gives): Vladik gives 1 candy to Valera. - Turn 2 (Valera gives): Valera gives 2 candies to Vladik. - Turn 3 (Vladik gives): Vladik gives 3 candies to Valera. - Turn 4 (Valera gives): Valera gives 4 candies to Vladik. - ... - On turn $ n $, the current player gives $ n $ candies to the other. **Important**: Candies received from the other player are **not** considered part of their own stock for the purpose of giving. That is, a player can only give candies from their **initial** stock — they cannot give candies they received in prior turns. Thus, at any turn $ n $, the player whose turn it is must have at least $ n $ candies from their original pile to give. Turns alternate: - Odd turns ($ n = 1, 3, 5, \dots $): Vladik gives. - Even turns ($ n = 2, 4, 6, \dots $): Valera gives. Define: - Let $ k $ be the turn number (starting at 1). - On turn $ k $, the player must give $ k $ candies. - Vladik can give on odd turns: $ k = 2m - 1 $ for $ m = 1, 2, 3, \dots $ - Valera can give on even turns: $ k = 2m $ for $ m = 1, 2, 3, \dots $ Vladik can make all his turns up to the largest odd integer $ k $ such that $ k \leq a $. Valera can make all his turns up to the largest even integer $ k $ such that $ k \leq b $. We need to find the **first** turn $ k $ where the player cannot give $ k $ candies. That is, find the smallest $ k \geq 1 $ such that: - If $ k $ is odd: $ a < k $ → Vladik fails. - If $ k $ is even: $ b < k $ → Valera fails. We are to determine the smallest $ k $ violating the condition, and report the player who fails on that turn. Thus, we compute: Let $ k_V $ be the largest odd integer such that $ k_V \leq a $ → Vladik can complete all odd turns up to $ k_V $. He fails on the next odd turn: $ k = k_V + 2 $, if $ k_V + 2 > a $. Actually, simpler: Vladik fails on the **first odd** $ k $ such that $ k > a $. That is, the smallest odd integer greater than $ a $. Similarly, Valera fails on the smallest even integer greater than $ b $. Let: - $ k_V = \min \{ k \in \mathbb{N} \mid k \text{ odd}, k > a \} $ - $ k_{Va} = \min \{ k \in \mathbb{N} \mid k \text{ even}, k > b \} $ Then: - If $ k_V < k_{Va} $, then Vladik fails first. - Else, Valera fails first. Compute: - $ k_V = \begin{cases} a + 1 & \text{if } a \text{ is even} \\ a + 2 & \text{if } a \text{ is odd} \end{cases} $ - $ k_{Va} = \begin{cases} b + 1 & \text{if } b \text{ is odd} \\ b + 2 & \text{if } b \text{ is even} \end{cases} $ Alternatively, more cleanly: - $ k_V = a + 1 + (a \bmod 2) $ - $ k_{Va} = b + 1 + (1 - b \bmod 2) $ But even simpler: The smallest odd integer > $ a $ is: $ k_V = a + 1 $ if $ a $ even, else $ a + 2 $ → $ k_V = a + 1 + (a \bmod 2) $ Similarly, smallest even integer > $ b $: $ k_{Va} = b + 1 $ if $ b $ odd, else $ b + 2 $ → $ k_{Va} = b + 1 + (1 - b \bmod 2) = b + 2 - (b \bmod 2) $ Alternatively, use: - $ k_V = 2 \left\lceil \frac{a + 1}{2} \right\rceil - 1 $ - $ k_{Va} = 2 \left\lceil \frac{b + 1}{2} \right\rceil $ But computationally, we can just compute: Let: - $ next\_odd\_after\_a = a + 1 $ if $ a $ even, else $ a + 2 $ - $ next\_even\_after\_b = b + 1 $ if $ b $ odd, else $ b + 2 $ Then compare: - If $ next\_odd\_after\_a < next\_even\_after\_b $ → Vladik fails first → output "Vladik" - Else → Valera fails first → output "Valera" **Formal Statement:** Given integers $ a, b \geq 1 $, define: - $ k_V = \begin{cases} a + 1 & \text{if } a \equiv 0 \pmod{2} \\ a + 2 & \text{if } a \equiv 1 \pmod{2} \end{cases} $ - $ k_{Va} = \begin{cases} b + 2 & \text{if } b \equiv 0 \pmod{2} \\ b + 1 & \text{if } b \equiv 1 \pmod{2} \end{cases} $ Then: - If $ k_V < k_{Va} $, output "Vladik" - Else, output "Valera"
Samples
Input #1
1 1
Output #1
Valera
Input #2
7 6
Output #2
Vladik
API Response (JSON)
{
  "problem": {
    "name": "A. Vladik and Courtesy",
    "description": {
      "content": "At regular competition Vladik and Valera won _a_ and _b_ candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was les",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF811A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "At regular competition Vladik and Valera won _a_ and _b_ candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was les...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "在常规比赛中,Vladik 和 Valera 分别赢得了 #cf_span[a] 和 #cf_span[b] 颗糖果。Vladik 向 Valera 赠送了 #cf_span[1] 颗糖果。之后,Valera 为了不让别人觉得他不够慷慨,回赠了 Vladik #cf_span[2] 颗糖果。接着,Vladik 为了同样的原因,在下一轮赠送了 #cf_span[3] 颗糖果给 Valera。\n\n更形...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Let $ a $ be the initial number of candies Vladik has, and $ b $ be the initial number of candies Valera has.\n\nThe exchange proceeds in turns, starting with Vladik:\n\n- Turn 1 (Vladik gives): Vladik gi...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments