Skip to content

3479. Fruits Into Baskets III #2018

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to efficiently allocate fruits to baskets following specific rules: each fruit must be placed in the leftmost available basket with a capacity greater than or equal to the fruit's quantity. The solution involves sorting the baskets by their capacity and original indices, then using a segment tree to efficiently query and update the smallest original index of available baskets that meet the capacity requirement for each fruit.

Approach

  1. Problem Analysis: The problem requires placing each fruit in the leftmost basket that can accommodate it (i.e., basket capacity >= fruit quantity). Each basket can hold only one type of fruit. The challenge is to efficiently determine, for each fru…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Aug 6, 2025
Maintainer Author

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Aug 6, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Aug 6, 2025
Maintainer Author

Answer selected by kovatz
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 medium Difficulty
2 participants