#include <iostream>
#include <vector>

using namespace std;

class Weapon {
protected:
    int damage;
    int uses;

public:
    Weapon(int damage, int uses) {
        this->damage = damage;
        this->uses = uses;
    }

    virtual int getDamage() = 0;
    virtual void decreaseUses() = 0;

    bool isUsable() {
        return (uses > 0);
    }
};

class Knife : public Weapon {
    float length;

public:
    Knife(int damage, int uses, float length) : Weapon(damage, uses) {
        this->length = length;
    }

    int getDamage() override {
        return damage * length;
    }

    void decreaseUses() override {
        uses--;
    }
};

class Bow : public Weapon {
    int arrows;

public:
    Bow(int damage, int uses, int arrows) : Weapon(damage, uses) {
        this->arrows = arrows;
    }

    int getDamage() override {
        return damage * arrows / 2;
    }

    void decreaseUses() override {
        uses -= 2;
    }
};

class Unarmed : public Weapon {
    int maxHP;

public:
    Unarmed(int maxHP) : Weapon(0, -1) {
        this->maxHP = maxHP;
    }

    int getDamage() override {
        return maxHP * 0.1;
    }

    void decreaseUses() override {
        maxHP -= maxHP * 0.1;
    }
};

class Beast {
protected:
    int HP;
    int damage;

public:
    Beast(int HP, int damage) {
        this->HP = HP;
        this->damage = damage;
    }

    virtual void attack(Weapon* weapon) = 0;

    bool isDefeated() {
        return (HP <= 0);
    }

    int getDamage() {
        return damage;
    }
};

class Cow : public Beast {
    int numAttacks;

public:
    Cow(int HP, int damage, int numAttacks) : Beast(HP, damage) {
        this->numAttacks = numAttacks;
    }

    void attack(Weapon* weapon) override {
        if (weapon->isUsable()) {
            HP -= weapon->getDamage();
            weapon->decreaseUses();
        }

        if (numAttacks > 0)
            numAttacks--;
    }

    bool isDefeated() {
        return (HP <= 0 || numAttacks <= 0);
    }
};

class Tiger : public Beast {
public:
    Tiger(int HP, int damage) : Beast(HP, damage) {}

    void attack(Weapon* weapon) override {
        if (weapon->isUsable()) {
            HP -= weapon->getDamage();
            weapon->decreaseUses();
        }
    }
};

int main() {
    int maxHP;
    cin >> maxHP;

    int numWeapons;
    cin >> numWeapons;

    vector<Weapon*> weapons;

    for (int i = 0; i < numWeapons; i++) {
        int type;
        int damage;
        int uses;
        float param;

        cin >> type >> damage >> uses >> param;

        Weapon* weapon;

        if (type == 1)
            weapon = new Knife(damage, uses, param);
        else if (type == 2)
            weapon = new Bow(damage, uses, static_cast<int>(param));
        else if (type == 3)
            weapon = new Unarmed(maxHP);

        weapons.push_back(weapon);
    }

    int numBeasts;
    cin >> numBeasts;

    vector<Beast*> beasts;

    for (int i = 0; i < numBeasts; i++) {
        int type;
        int HP;
        int damage;
        int numAttacks;

        cin >> type >> HP >> damage;

        Beast* beast;

        if (type == 1) {
            cin >> numAttacks;
            beast = new Cow(HP, damage, numAttacks);
        }
        else if (type == 2)
            beast = new Tiger(HP, damage);

        beasts.push_back(beast);
    }

    for (size_t i = 0; i < beasts.size(); i++) {
        Beast* currentBeast = beasts[i];

        for (size_t j = 0; j < weapons.size(); j++) {
            Weapon* currentWeapon = weapons[j];

            while (!currentBeast->isDefeated() && currentWeapon->isUsable()) {
                currentBeast->attack(currentWeapon);

                if (!currentBeast->isDefeated()) {
                    // A Phu receives counter-attack
                    maxHP -= currentBeast->getDamage();
                }
            }
        }
    }

    int remainingWeapons = 0;

    for (size_t i = 0; i < weapons.size(); i++) {
        if (weapons[i]->isUsable())
            remainingWeapons++;
    }

    if (maxHP > 0 && remainingWeapons > 0)
        cout << "A Phu chien thang, hp con lai: " << maxHP << ", so vu khi con lai: " << remainingWeapons << endl;
    else
        cout << "A Phu that bai, so thu du con lai: " << beasts.size()-1 << endl;

    return 0;
}
Your code did not pass this test case.

Input (stdin)

100
3
1 20 3 1.5
1 30 2 2
2 3 3 4
3
1 100 3 3
2 40 2
2 10 2
Your Output (stdout)

A Phu that bai, so thu du con lai: 2
Expected Output

A Phu chien thang, hp con lai: 94, so vu khi con lai: 1
Compiler Message

Wrong Answer