From 6805ce071a17133bf34312edd0345e35c4f03093 Mon Sep 17 00:00:00 2001 From: ckj7879 <102664166+ckj7879@users.noreply.github.com> Date: Wed, 30 Mar 2022 16:49:03 +0530 Subject: [PATCH] Create Chinmay_Goodies --- Chinmay_Goodies | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Chinmay_Goodies diff --git a/Chinmay_Goodies b/Chinmay_Goodies new file mode 100644 index 0000000..5ed55d5 --- /dev/null +++ b/Chinmay_Goodies @@ -0,0 +1,59 @@ +import java.io.*; +import java.util.*; + +public class Goodies +{ + static int Find_Elements(int res,int array[],int N,int M) + { + int result=Integer.MAX_VALUE; + for(int i=0;i<=N;i++) + { + result=Math.min(result,array[i+M-1]-array[i]); + if(res==result) + { + return i; + } + + } + return 0; + } + + static int mn_dif(int array[], int N, int M) + { + int result=Integer.MAX_VALUE; + Arrays.sort(array); + for(int i=0;i<=N-M;i++) + { + result= Math.min(result, array[i+M-1] - array[i]); + } + return result; + + } + public static void main(String[] arg) + { + int array[]={7980,22349,999,2799,229900,11101,9999,2195,9800,4999}; + String items[]={"MI Band : 999","Sandwich Toaster : 2195","Cult Pass :2799","Scale : 4999","Fitbit Plus : 7980", + "Microwave Oven : 9800","Alexa : 9999","Digital Camera : 11101","IPods : 22349","Macbook Pro : 229900" }; + + int N=array.length; + System.out.print("\n Enter The Number Of Employees : "); + Scanner ss=new Scanner(System.in); + + int M=ss.nextInt(); + + int result=mn_dif(array,N,M); + + System.out.println("Number Of Employees is :: "+M); + + int start_index=Find_Elements(result,array,N,M); + System.out.println("Here the goodies that are selected for distribution are :: "); + for(int i=start_index;i