[20251218] BOJ / G4 / 드래곤 앤 던전 / 이인희#1708
Merged
LiiNi-coder merged 1 commit intomainfrom Dec 18, 2025
Merged
Conversation
Contributor
Author
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] temp = br.readLine().split(" ");
int N = Integer.parseInt(temp[0]);
long attack = Long.parseLong(temp[1]);
long currentHp = 0; //현재 체력 변화량 (음수면 데미지 누적)
long maxHpNeeded = 0; //지금까지 필요했던 최대 체력
for (int i = 0; i < N; i++) {
temp = br.readLine().split(" ");
int type = Integer.parseInt(temp[0]);
long a = Long.parseLong(temp[1]);
long h = Long.parseLong(temp[2]);
if(type == 1) {
//몬스터를 죽이려면 ceil(h / attack) 번 공격해야 함
//용사는 (공격횟수 - 1) 번 맞음
long attackCount = (int)Math.ceil((h / (double)attack));
long damageTaken = (attackCount - 1) * a;
currentHp -= damageTaken;
//현재 HP가 1 이상이어야 하므로, 필요한 최소 시작 HP 갱신해야함 -> currentHp가 음수면 그만큼 더 필요
//currentHp = -100, 시작 HP가 최소 101이어야 함
if (-currentHp + 1 > maxHpNeeded) {
maxHpNeeded = -currentHp + 1;
}
}else{
attack += a;
currentHp += h;
//회복은 MaxHP를 초과할 수 없음
if (currentHp > 0) {
currentHp = 0;
}
}
}
System.out.println(maxHpNeeded);
br.close();
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/16434
🧭 풀이 시간
60 분
👀 체감 난이도
✏️ 문제 설명
🔍 풀이 방법
⏳ 회고