I just started looking at the problem BUYING SWEET my hunch tells me that correct condition/logic to solve the above problem is this …

(sum % total_sweet) if find any note else then remainder then the customer is not an adequate customer. Work properly on the all the Test case found

Test case 1

4 7
10 4 8 5

[10,4,8 ,5].sum
## sum is 27
rem = 27 % 7  6
#### rem = 6
i = 0;
for i < a.length:
if a[i] < 6
break

Test Case 2

1 10
12

[12].sum
rem = 12%10
## rem is 2
No number less them 2 hence customer is adequate.

Test Case 3

2 10
20 50

[20, 50].sum
## 70
rem = 70 % 10
## 0
No number less then 0

But with Limited Test case I’m not sure if the above logic is correct can some please provide some more TEST case so that I can verify them.

EDITED:
I just wrote the initial implementation Getting WRONG ANSWER but the editorial https://discuss.codechef.com/questions/3250/buying2-editorial matched with my belief.

Here the Code I submitted https://www.codechef.com/viewsolution/15221523

The logic seems pretty much fine to me. You can go and code with this approach. It works for test cases like-

3 20
6 6 10

3 4
2 2 1

4 15
7 4 2 3

Take care of implementation though. Often faulty implementation cause frustrating WAs.

Your code fails for this test case-

Input
1
5 5
1 1 1 1 2