Tap here to switch tabs
Problem
Submissions

Problem: Maximum Coins From K Consecutive Bags

med
30 min
Try to solve the Maximum Coins From K Consecutive Bags problem.

Statement

You are given a 22D integer array coins and an integer k. Each element coins[i] =[li,ri,ci]= [l_i, r_i, c_i] represents a contiguous range of bags from position lil_i to rir_i inclusive, where each bag contains cic_i coins. Any position that does not fall into any segment contains 00 coins.

You want to collect coins from a sequence of k consecutive bags.

Return the maximum total number of coins you can collect from any window of k consecutive bags.

Constraints:

  • 1≤1 \leq coins.length ≤105\leq 10^5

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

  • coins[i] =[li,ri,ci]= [l_i, r_i, c_i]

  • 1≤li≤ri≤1091 \leq l_i \leq r_i \leq 10^9

  • 1≤ci≤10001 \leq c_i \leq 1000

  • The given segments do not overlap.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Coins From K Consecutive Bags

med
30 min
Try to solve the Maximum Coins From K Consecutive Bags problem.

Statement

You are given a 22D integer array coins and an integer k. Each element coins[i] =[li,ri,ci]= [l_i, r_i, c_i] represents a contiguous range of bags from position lil_i to rir_i inclusive, where each bag contains cic_i coins. Any position that does not fall into any segment contains 00 coins.

You want to collect coins from a sequence of k consecutive bags.

Return the maximum total number of coins you can collect from any window of k consecutive bags.

Constraints:

  • 1≤1 \leq coins.length ≤105\leq 10^5

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

  • coins[i] =[li,ri,ci]= [l_i, r_i, c_i]

  • 1≤li≤ri≤1091 \leq l_i \leq r_i \leq 10^9

  • 1≤ci≤10001 \leq c_i \leq 1000

  • The given segments do not overlap.