BUYING2 SWEET

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

Answer

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

Customer is not adequate

Test Case 2

1 10
12

Answer

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

Test Case 3

2 10
20 50

Answer

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

Customer is adequate.

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
Your Output
1
Expected Output
-1

We can remove any ā€œ1ā€ note and still buy the sweet.

@vijju123 I clear miss less than equality sign as compare to less than. Thanks

1 Like