---
# System prepended metadata

title: Bài 1

---

# Bài 1

```cpp=
/*
a / 1 luot
b / m luot
c / k luot
n so luot can mua

in  n m k | a b c
out so tien it nhat de di duoc n luot

in  9 2 3 | 1 3 3
out 9

in  5 2 4 | 4 5 13
out 14

-> a | b | c phai nho nhat
->  n | k phai lon nhat

*/

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n(5), m(2), k(4), a(4), b(5), c(13);
    int money = 0;

    while (n > 0)
    {
        if (c - k <= b - m && n - k >= 0)
        {
            money += c;
            n -= k;
        }
        else if (b - m <= a - 1 && n - m >= 0)
        {
            money += b;
            n -= m;
        }
        else
        {
            money += a;
            n--;
        }
    }

    cout << money << endl;
    return 0;
}
```

