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} });
}'프로그래머스 > 코딩테스트' 카테고리의 다른 글
| LV1, Kakao) 개인정보 수집 유효기간 (0) | 2026.08.17 |
|---|---|
| LV2 sql ) 부모의 형질을 모두 가지는 대장균 찾기 (0) | 2026.08.15 |
| lv1 sql) 특정 형질을 가지는 대장균 찾기 (0) | 2026.08.08 |
| lv1) 중요한 단어를 스포 방지 [정답률 가장 낮은 문제] (0) | 2026.08.05 |
| lv3) 입국심사 [다시] (0) | 2026.07.19 |