F. Deposit

Codeforces
IDCF10279F
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Monocarp saved up $n$ burles and decided to deposit all his $n$ burles in a local bank. Unfortunately, Monokarp hasn't read the license agreement, that's why now he has only two types of operations with money in the deposit (fortunately, he can make any number of operations of each type): Assume that Monocarp put all his $n$ burles in the bank account and he has no more money left, so he can work only with money he put in the bank. Calculate the maximum possible amount of burles Monocarp can obtain from his bank account using only described operations. The first line contains three integers $n$, $a$, and $b$ ($1 <= a, b <= n <= 10^6$) — the number of burles Monocarp deposited initially, the number of burles he can withdraw from the account in one operation, and the number of burles he can deposit to the account in one operation. Print the maximum possible amount of burles Monocarp can obtain from his bank account using only operations described in the statement. ## Input The first line contains three integers $n$, $a$, and $b$ ($1 <= a, b <= n <= 10^6$) — the number of burles Monocarp deposited initially, the number of burles he can withdraw from the account in one operation, and the number of burles he can deposit to the account in one operation. ## Output Print the maximum possible amount of burles Monocarp can obtain from his bank account using only operations described in the statement. [samples]
**Definitions** Let $ n, a, b \in \mathbb{Z}^+ $ with $ 1 \leq a, b \leq n < 10^6 $. Let $ x \in \mathbb{Z}_{\geq 0} $ be the number of withdrawal operations (each withdrawing $ a $ burles). Let $ y \in \mathbb{Z}_{\geq 0} $ be the number of deposit operations (each depositing $ b $ burles). **Constraints** 1. The account balance must never go negative: $$ n - a \cdot x + b \cdot y \geq 0 $$ 2. All operations are non-negative integers: $$ x \geq 0, \quad y \geq 0 $$ **Objective** Maximize the final account balance: $$ \max \left( n - a \cdot x + b \cdot y \right) $$
API Response (JSON)
{
  "problem": {
    "name": "F. Deposit",
    "description": {
      "content": "Monocarp saved up $n$ burles and decided to deposit all his $n$ burles in a local bank. Unfortunately, Monokarp hasn't read the license agreement, that's why now he has only two types of operations w",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10279F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Monocarp saved up $n$ burles and decided to deposit all his $n$ burles in a local bank.\n\nUnfortunately, Monokarp hasn't read the license agreement, that's why now he has only two types of operations w...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, a, b \\in \\mathbb{Z}^+ $ with $ 1 \\leq a, b \\leq n < 10^6 $.  \nLet $ x \\in \\mathbb{Z}_{\\geq 0} $ be the number of withdrawal operations (each withdrawing $ a $ burles).  \nLet...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments