Maximum Sum Segment

You are given an array a of n positive integers. You Have to perform Q query on it. In each query, you will be given three positive integers l, r, k. In response to the query you have to tell the maximum number of elements you can choose from the segment [l, r] such that their sum is not more than k.

This is a companion discussion topic for the original entry at