A. Generous Eater

Codeforces
IDCF10219A
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You have n candies. You want to give as much to your friends as possible, but you have a problem; every time you give two friends a candy each, you can't help but eat one yourself (if you have one left). You tried to resist after giving the first one, but after giving the second, it was unbearable. What is the maximum number of friends you can give candies to? The first line of input contains n (1 ≤ n ≤ 109), the number of candies you have. Output a single line with the maximum number of friends you can give candies to. ## Input The first line of input contains n (1 ≤ n ≤ 109), the number of candies you have. ## Output Output a single line with the maximum number of friends you can give candies to. [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be the number of candies, with $ 1 \leq n \leq 10^9 $. **Constraints** For every two candies given to two friends, one candy is consumed by the giver (i.e., a cost of 1 candy per 2 friends). **Objective** Maximize the number of friends $ f \in \mathbb{Z}_{\geq 0} $ such that: $$ f \leq 2 \left\lfloor \frac{n}{3} \right\rfloor + \min\left(n \bmod 3, 1\right) $$ Equivalently: $$ f = \left\lfloor \frac{2n}{3} \right\rfloor $$
API Response (JSON)
{
  "problem": {
    "name": "A. Generous Eater",
    "description": {
      "content": "You have n candies. You want to give as much to your friends as possible, but you have a problem; every time you give two friends a candy each, you can't help but eat one yourself (if you have one lef",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10219A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You have n candies. You want to give as much to your friends as possible, but you have a problem; every time you give two friends a candy each, you can't help but eat one yourself (if you have one lef...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of candies, with $ 1 \\leq n \\leq 10^9 $.\n\n**Constraints**  \nFor every two candies given to two friends, one candy is consumed by the giver (i.e...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments