From 861708fcd39d449ddaac1579f7ef014fb68bce5e Mon Sep 17 00:00:00 2001 From: sh0723 Date: Wed, 2 Sep 2026 19:43:31 +0900 Subject: [PATCH] =?UTF-8?q?16434=20:=20=EB=93=9C=EB=9E=98=EA=B3=A4=20?= =?UTF-8?q?=EC=95=A4=20=EB=8D=98=EC=A0=84=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week6/BOJ16434/BOJ16434_V1.cpp | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/week6/BOJ16434/BOJ16434_V1.cpp diff --git a/src/week6/BOJ16434/BOJ16434_V1.cpp b/src/week6/BOJ16434/BOJ16434_V1.cpp new file mode 100644 index 0000000..ab0b0be --- /dev/null +++ b/src/week6/BOJ16434/BOJ16434_V1.cpp @@ -0,0 +1,59 @@ +#include +using namespace std; +long long int HmaxHP,HcurHP,HATK,N; +struct room_struct{ + int type,atk,hp; +}; +vector rooms; +bool check_valid() { + long long int temp_atk = HATK; + for (room_struct room : rooms) { + if (room.type == 1) { + if(room.hp <= temp_atk) continue; + else { + long long hitCount = (room.hp - 1) / temp_atk; + long long need = hitCount * room.atk; + + if (HcurHP <= need) return false; + else { + HcurHP -= need; + } + } + } else { + temp_atk += room.atk; + HcurHP = min(HmaxHP, HcurHP + room.hp); + } + } + return true; +} +long long int ret = LLONG_MAX; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + cin >> N >> HATK; + + for (int i=0; i> t >> a >> h; + rooms.push_back({t,a,h}); + } + + long long int high = 1e18, low = 1; + while(low <= high) { + HmaxHP = (high + low) / 2; + HcurHP = HmaxHP; + + if (check_valid()) { + ret = min(ret, HmaxHP); + high = HmaxHP-1; + } else { + low = HmaxHP+1; + } + } + + cout << ret << '\n'; + return 0; +} \ No newline at end of file