Skip to content

Conversation

@LiiNi-coder
Copy link
Contributor

@LiiNi-coder LiiNi-coder commented Dec 18, 2025

🧷 문제 링크

https://www.acmicpc.net/problem/16434

🧭 풀이 시간

60 분

👀 체감 난이도

✏️ 문제 설명

  • 몬스터방을 지나칠때마다 몬스터를 잡는데에 체력이 까인다. 맨 초기 체력이 최소 얼마나 되어야 끝까지 깰수있는가

🔍 풀이 방법

  • 역산하는 시뮬레이션

⏳ 회고

  • 이렇게 해서 시간이 없어서 못풀었다. 완성시킨 방법을 다시 댓글로 올리겠습니다

@LiiNi-coder LiiNi-coder merged commit bd86ba4 into main Dec 18, 2025
1 check passed
@LiiNi-coder LiiNi-coder added the fail 😢 해설을 보고 풀었거나, 못 풀었을 때 label Dec 18, 2025
@LiiNi-coder
Copy link
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();
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fail 😢 해설을 보고 풀었거나, 못 풀었을 때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants