๐ง Goal: In this challenge, we must help the dragons defeat Malakar by simulating attacks. Each attack is represented by a list of potential damage values, and the objective is to select one value per round (sub-list) such that the total damage equals a given target. A unique solution is always guaranteed.
๐ Input Analysis:
The input consists of two elements:
๐งช Example:
[[13, 15, 27, 17], [24, 15, 28, 6, 15, 16], [7, 25, 10, 14, 11], [23, 30, 14, 10]] 77
๐ We are looking for one value from each sublist that adds up to 77.
๐งฉ Strategy: Classic recursive backtracking:
๐ง Python Code:
import ast rounds = ast.literal_eval(input().strip()) target = int(input().strip()) def find_combo(rounds, index, current_sum, path): if index == len(rounds): if current_sum == target: return path return None for dmg in rounds[index]: result = find_combo(rounds, index + 1, current_sum + dmg, path + [dmg]) if result: return result return None result = find_combo(rounds, 0, 0, []) if result: print(result)
โ
Test Example:
Input: [[12, 14, 6, 5, 24], [16, 29], [6, 17]]
Target: 70 โ Result: [24, 29, 17]
๐ Flag:
HTB{DR4GONS_FURY_SIM_COMBO_d58c80a8e04bddf6251c269ba74ca116}
๐ Challenge Description:
In the mystical realm of the Floating Isles, dragons must fly from one sanctuary to another. However, shifting winds can either help or hinder them.
Your task is to calculate the maximum distance a dragon can travel across a flight segment, taking into account:
๐ฏ Objective: Handle two types of operations:
Q l r
: Returns the maximum subarray sum between indices l
and r
(inclusive).U i x
: Updates the wind value at position i
to x
.๐ฅ Sample Input:
6 6 -10 -7 -1 -4 0 -5 Q 3 3 U 2 9 Q 6 6 U 1 -1 Q 6 6 U 5 -9
๐ค Expected Output:-1
-5
-5
๐ง Strategy: We use Kadaneโs algorithm to find the maximum subarray sum on demand, and directly apply updates with simple assignment for the U
operations.
๐งช Code Used:
n, q = map(int, input().split()) wind = list(map(int, input().split())) ops = [input() for _ in range(q)] def max_sub_sum(arr): max_sum = curr = arr[0] for x in arr[1:]: curr = max(x, curr + x) max_sum = max(max_sum, curr) return max_sum for op in ops: if op[0] == 'Q': _, l, r = op.split() l, r = int(l) - 1, int(r) print(max_sub_sum(wind[l:r])) else: _, i, x = op.split() wind[int(i) - 1] = int(x)
๐ Flag: HTB{DR4G0N_FL1GHT_STR33_a5bf2a2a21e23ffd412a5fb76f2a37ce}
๐งพ WorkUp โ Clockwork Guardian
๐ง Goal: Write an algorithm to find the shortest safe path in a grid representing a tower guarded by sentinels. The journey begins at cell (0, 0), and the goal is to reach the exit marked 'E', avoiding any cells marked as 1 (hostile sentinels).
๐ Problem Analysis:
0
โ Empty cell, walkable.1
โ Sentinel (blocked cell).'E'
โ Exit.Movement is 4-directional: up, down, left, right. The goal is to minimize the number of steps required to reach the exit, without stepping on a sentinel.
๐ ๏ธ Chosen Approach: Breadth-First Search (BFS)
๐งช Example Grid:
[ [0, 0, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 'E'] ]
โ
Expected Output: 8
Optimal path: from (0,0) to 'E' in 8 steps.
๐ง Python Code:
import ast from collections import deque grid = ast.literal_eval(input()) rows = len(grid) cols = len(grid[0]) directions = [(-1,0), (1,0), (0,-1), (0,1)] start = (0, 0) for i in range(rows): for j in range(cols): if grid[i][j] == 'E': end = (i, j) visited = [[False]*cols for _ in range(rows)] queue = deque([(start[0], start[1], 0)]) visited[start[0]][start[1]] = True while queue: x, y, dist = queue.popleft() if (x, y) == end: print(dist) break for dx, dy in directions: nx, ny = x + dx, y + dy if 0 <= nx < rows and 0 <= ny < cols: if not visited[nx][ny] and grid[nx][ny] != 1: visited[nx][ny] = True queue.append((nx, ny, dist + 1))
๐ Flag: HTB{CL0CKW0RK_BFS_M4ST3RY}
โ
Intro : As the mists part, we find ourselves at the gates of the Dragonโs Heart, facing an ancient interface veiled in mystery and magic. The quest before us is clear: combine magical tokens to unlock the hidden energy withinโฆ but beware โ combining two adjacent tokens causes them to lose their power.
๐ช Step 1: Understanding the Ritual
We are given a list of integers representing token energies, and must find the maximum sum of non-adjacent tokens.
This is a classic Dynamic Programming problem, disguised in a fantasy setting.
โ๏ธ Step 2: The Incantation (Code Logic)
We evaluate the input list:
- If it's empty โ return 0
- One token โ return that
- Otherwise โ use two accumulators:
prev1 = max sum including previous
prev2 = max sum excluding previous
Then we iterate through the list:
curr = max(prev1, prev2 + token)
๐งช Step 3: Testing the Magic
Input: [20, 9, 15, 3, 3, 10, 12]
Optimal: 20 + 15 + 10 + 5 = 50
โ
Maximum non-adjacent sum: 50
๐ Final Flag :
HTB{SUMMON3RS_INC4NT4TION_R35OLV3D_f64c9ae90d81f7240ddaa7b1d0245808}
The spell is complete. The path is clear. The Dragonโs Heart stirs once more. ๐ฅ
nums = eval(input()) # Example: [3, 2, 5, 10, 7] if not nums: print(0) elif len(nums) == 1: print(nums[0]) else: prev1, prev2 = nums[0], 0 for i in range(1, len(nums)): curr = max(prev1, prev2 + nums[i]) prev2 = prev1 prev1 = curr print(prev1)