Tap here to switch tabs
Problem
Submissions

Problem: Total Score of Dungeon Runs

Try to solve the Total Score of Dungeon Runs problem.

Statement

You are given an integer hp representing your initial health points, and two integer arrays damage and requirement, each of length n.

A dungeon contains n rooms numbered from 00 to n −1- 1. You can choose to start a run from any room i (0≤0 \le i << n) with an initial health of hp points and visit the rooms sequentially from room i to room n −1- 1.

In each run starting from room i:

  • When you enter room j (i ≤\le j << n), your health points decrease by damage[j].

  • If your remaining health points after taking damage are greater than or equal to requirement[j], you earn 11 point.

Let score(i) be the total points earned when starting the run from room i.

Return the total score obtained by summing score(i) across all possible starting rooms i from 00 to n −1- 1.

Constraints:

  • 1≤1 \leq hp ≤109\leq 10^9

  • 1≤1 \leq n ==== damage.length ==== requirement.length ≤105\leq 10^5

  • 1≤1 \leq damage[i], requirement[i] ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Total Score of Dungeon Runs

Try to solve the Total Score of Dungeon Runs problem.

Statement

You are given an integer hp representing your initial health points, and two integer arrays damage and requirement, each of length n.

A dungeon contains n rooms numbered from 00 to n −1- 1. You can choose to start a run from any room i (0≤0 \le i << n) with an initial health of hp points and visit the rooms sequentially from room i to room n −1- 1.

In each run starting from room i:

  • When you enter room j (i ≤\le j << n), your health points decrease by damage[j].

  • If your remaining health points after taking damage are greater than or equal to requirement[j], you earn 11 point.

Let score(i) be the total points earned when starting the run from room i.

Return the total score obtained by summing score(i) across all possible starting rooms i from 00 to n −1- 1.

Constraints:

  • 1≤1 \leq hp ≤109\leq 10^9

  • 1≤1 \leq n ==== damage.length ==== requirement.length ≤105\leq 10^5

  • 1≤1 \leq damage[i], requirement[i] ≤104\leq 10^4