[Programmers]_C++_Algorithm_붕대감기

신치우·2025년 2월 17일

C++_algorithm

목록 보기
6/17
#include <string>
#include <vector>

using namespace std;

int solution(vector<int> bandage, int health, vector<vector<int>> attacks) {
    
    int answer = 0;
    int time = 0;
    int conti = 0;
    int attack_order = 0;
    int health_x = health;
    
    while(attack_order<attacks.size()){
        time++;
        conti++;
        if(attacks[attack_order][0] == time){
            health -= attacks[attack_order][1];
            if(health <=0)
                return -1;
            conti = 0;
            
            attack_order++;
        } else {
            if(conti == bandage[0]){
                health += bandage[1] + bandage[2];
                if(health > health_x)
                    health = health_x;
                conti = 0;
            } else {
                health += bandage[1];
                if(health > health_x)
                    health = health_x;
            }
        }
    }
    answer = health;
    
    
    return answer;
}
profile
https://shin8037.tistory.com/

0개의 댓글