https://school.programmers.co.kr/learn/courses/30/lessons/250137

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

int solution(vector<int> bandage, int health, vector<vector<int>> attacks) {
    int answer = 0;
    int maxi = health;
    //bandage[1] 초마다 증가 5초(bandage[0] 만큼) 연속 체력이 증가시 +5(bandage[2])만큼 추가 회복 후 연속 성공 초기화
    // 단 attacks (몬스터 공격 있을 시) 연속 성공이 초기화
    // 체력(health) 0이하가 되면 -1리턴
    //최대 체력 health 만큼 증가
    int n = attacks.size();
    int cnt = 1; // 연속 성공 카운팅
    //연속성공초기화 조건 attack 받거나, bandage[0]로연속증가시

    int attack_idx = 0;
    for (int t = 1; t <= attacks[n-1][0]; ++t) {

        if (attacks[attack_idx][0] == t) {
            health -= attacks[attack_idx][1];
            if (health <= 0)return -1;
            attack_idx++;
            cnt = 0;
            continue;
        }
        cnt++;
        health += bandage[1];
        if (health >= maxi) health = maxi;
        if (cnt >= bandage[0]) {
            health += bandage[2];
            cnt = 0;
        }
        if (health >= maxi) {
            health = maxi;
        }
        
    }

    return health;
}

int main(void) {
    solution({ 1,1,1 }, 5, { {1,2},{3,2} });
}

+ Recent posts