Menu Close

Help Mommy out …fcukthecode

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.

Input:
Testcases:  1
Minutes:  10
Seconds:  20
Plates:  5
Sizes of the Plates:  10 12 9 8 11

Output:
1 - Task Complete
import java.io.*;
import java.util.*;
public class temp{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    System.out.print("Enter no: of testcases:  ");
    int t=sc.nextInt();

    for(int k=0;k<t;k++){
      System.out.print("Enter no: of Minutes:  ");
      int min=sc.nextInt();
      System.out.print("Enter no: of Seconds:  ");
      int sec=sc.nextInt();
      System.out.print("Enter no: of Plates:  ");
      int n=sc.nextInt();

      int[] a=new int[n];
      System.out.print("Enter the sizes of the Plates (Array):  ");
      for(int i=0;i<n;i++){
        a[i]=sc.nextInt();
      }

      int mintosec = min*60;
      int count=0,temp=0;

      for (int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
          if(a[i]>a[j]){
            count++;
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
          }
        }
      }

      int reqsec=sec*count;
      if(reqsec<mintosec)
      System.out.println("1 - Task Complete");
      else System.out.println("0 - Task Not Complete");
    }
  }
}

INPUT_1:
Enter no: of testcases:  3
Enter no: of Minutes:  20
Enter no: of Seconds:  15
Enter no: of Plates:  5
Enter the sizes of the Plates (Array):  35  10  85  90  30
OUTPUT:
1 – Task Complete

Enter no: of Minutes:  10
Enter no: of Seconds:  30
Enter no: of Plates:  10
Enter the sizes of the Plates (Array):  48  14  37  29  30  47  11  23  25  8
OUTPUT:
0 – Task Not Complete

Enter no: of Minutes:  5
Enter no: of Seconds:  40
Enter no: of Plates:  8
Enter the sizes of the Plates (Array):  25  28  12  20  6  5  37  26
OUTPUT:
0 – Task Not Complete


INPUT_2:
Enter no: of testcases:  3
Enter no: of Minutes:  20
Enter no: of Seconds:  15
Enter no: of Plates:  5
Enter the sizes of the Plates (Array):  35  10  85  90  30
OUTPUT:
1 – Task Complete

Enter no: of Minutes:  20
Enter no: of Seconds:  15
Enter no: of Plates:  5
Enter the sizes of the Plates (Array):  35  10  85  90  31
OUTPUT:
1 – Task Complete

Enter no: of Minutes:  12
Enter no: of Seconds:  2
Enter no: of Plates:  2
Enter the sizes of the Plates (Array):  12  43  34  17  97
OUTPUT:
1 – Task Complete


INPUT_3:
Enter no: of testcases:  2
Enter no: of Minutes:  10
Enter no: of Seconds:  20
Enter no: of Plates:  5
Enter the sizes of the Plates (Array):  10  12  9  8  11
OUTPUT:
1 – Task Complete

Enter no: of Minutes:  5
Enter no: of Seconds:  5
Enter no: of Plates:  4
Enter the sizes of the Plates (Array):  6  8  9  11
OUTPUT:
1 – Task Complete


ILLUSTRATION

Executed using javac on linux terminal