Timer is Running

Help Mommy out
##### Submissions: 1080   Accuracy: 38.34%   Difficulty: Easy   Marks: 2

Mommy is a very active lady. She likes to keep all stuff sorted. She has developed an interesting technique of sorting stuff over the years. She goes through the items repeatedly from first to last and whenever she finds two consecutive items unsorted, she puts them in the proper order. She continues the process until all the items are sorted. One day Mommy has to attend a wedding ceremony. Suddenly she remembers that she has not sorted the plates after washing. She has only M minutes left. If she can complete the task within the remaining time, she will sort her plates and then attend the wedding. However if she cannot, she decides to skip the task. She knows that she take S seconds per swap. However she does not know the total number of swaps required and hence she is in trouble. She wants you to help her out.

Input:
The first line of input takes the number of test cases T .Then T test cases follow .
Each test case contains 2 lines . The first line of each test case contains  3 space separated integers M,S and N, where N is the number of plates .The next line of the test case contains N space separated values which denotes the size of the plates .

Output:

Print 1 if mommy can complete the task, 0 otherwise.

Constraints:

1<=T<=100

1<=M<=100

1<=S<=100

1<=N<=100

1<=Size of Plate<=200

Example:

Input:
3
20 15 5
35 10 85 90 30
10 30 10
48 14 37 29 30 47 11 23 25 8
5 40 8
25 28 12 20 6 5 37 26

Output:
1
0
0

Explanation:

Test Case#1

Iteration                       Array                          Swaps                   Time

1                   10 35 85 30 90                        2                          30

2                   10 35 30 85 90                        1                          15

3                   10 30 35 85 90                        1                          15

Total Time Taken = 60 seconds = 1 minute < 20 minutes.

Hence Mommy can complete the task right now and the output is 1.

The remaining test cases follow from the same logic.

#### ** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Arpan Kundu
Author: akundusaltlake

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.