We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/**
*
*
* @author manuss
*
*/
public class Solution {
static BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
static StringBuilder out = new StringBuilder();
public static void main(String[] args) throws NumberFormatException, IOException {
int numPackets = Integer.parseInt(in.readLine());
int numKids = Integer.parseInt(in.readLine());
int[] packets ;
Set<Integer> set = new TreeSet<Integer>();
for(int i = 0; i < numPackets; i ++)
{
set.add(Integer.parseInt(in.readLine()));
}
packets = new int[numKids];
int i=0;
for(int val:set){
if(i==numKids){
break;
}
packets[i++] = val;
}
System.out.println(packets[packets.length-1]-packets[0]);
}
}
Max Min
You are viewing a single comment's thread. Return to all comments →
Well I am getting 2000 for the 3rd test case in my local machine. But the answer says it should be 1335? I dont get it. Whats wrong with my code?
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Set; import java.util.TreeSet;
/** * * * @author manuss * */ public class Solution { static BufferedReader in = new BufferedReader(new InputStreamReader( System.in)); static StringBuilder out = new StringBuilder();