I encountered the same problem in three online assesment. Unfortuntely, I was not able to solve it in all three cases.
Your friend has N different kind of candies each present in Mi units (i = 1 to N). He is allowed to eat only one type of candy every day. Since he likes some candies more than the others, he gives each type of candy a priority and eats the higher priority candies first. However, there is a limit to it that he cannot eat more than k candies in one day (i.e. he may eat 1 or 2, … or K candies in a day.
He asks you if somehow, he would be able to eat Xth type of candy on the Yth day.
Note: He can only eat candy with priority p, after eating all the candies of priority p+1 and no two types of candies will have same priorities i.e priorities are distinct.
[5, 2, 6, 4, 1] -> Candy count
[1, 2, 3, 4, 5] -> Priority
X Y Result (Query)
5 1 -> YES
4 4 -> YES
3 16 -> NO
1 16 -> YES
2 8 -> YES
1 <= N, K and Queries <= 10^5
1 <= Mi <= 10^12
1 <= X <= N
1 <= Y <= 10^16
Any help is appreciated.