๐Ÿ”ฅ Dragonโ€™s Fury Simulation

๐Ÿง  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}

๐ŸŒ€ Dragon Flight Path

๐Ÿ”Ž 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:

๐Ÿ“ฅ 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}

โš™๏ธ Clockwork Guardian

๐Ÿงพ 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:

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} โœ…

๐Ÿ”ฎ Enchanted Cipher

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)
        
```