Skip to content

2551. Put Marbles in Bags #1501

Answered by mah-shamim
mah-shamim asked this question in Q&A
Mar 31, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

We need to determine the difference between the maximum and minimum possible scores when distributing marbles into k bags. Each bag must contain contiguous subarrays of marbles, and the score for each bag is the sum of the first and last marble's weight in that bag.

Approach

  1. Understanding the Problem Constraints: Each bag must be a contiguous subarray. The score for each bag is the sum of the first and last elements of the subarray. The goal is to find the difference between the maximum and minimum scores possible with k bags.

  2. Key Insight: The score for each bag can be determined by the sum of the first and last elements of each subarray. When splitting the array into k contiguous sub…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Mar 31, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants