#include<stdio.h> int main() { int a[1001]; int n,i,j,t,swap,temp,k,m,s,r; scanf("%d", &t); while(t){ swap=0; scanf("%d %d %d", &m,&s,&n); for(i=0; i<n; i++){ scanf("%d", &a[i]); } for(i=0; i<n1; i++){ //temp=i; for(j=0;j<ni1;j++){ //temp=a[j]; if(a[j]>a[j+1]){ temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; swap++; } } } r=swap*s; if(r<=m*60){ printf("1"); } else{ printf("0"); } printf("\n"); } return 0; }
Problem Description
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

Test Case 1
Input (stdin)
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
Expected Output
1 0 0

Test Case 2
Input (stdin)
2 20 15 35 10 85 90 30 10 30 48 14 37 29 30 47 11 23 25 8
Expected Output
0 1