import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class A { private static class Student implements Comparable { private int id; private double gpa; public Student(int id, double gpa) { super(); this.gpa = gpa; this.id = id; } public boolean equals(Object object) { final double EPSILON = 0.01; boolean equal; if (object != null && this.getClass() == object.getClass()) { Student other = (Student) object; equal = (this.id == other.id) && Math.abs(this.gpa - other.gpa) < EPSILON; } else { equal = false; } return equal; } public int compareTo(Student other) { final double EPSILON = 0.01; final int FACTOR = 100; int difference; if (Math.abs(this.gpa - other.gpa) < EPSILON) { difference = this.id - other.id; } else { difference = (int) (FACTOR * (other.gpa - this.gpa)); } return difference; } public String toString() { return "" + this.id; } } public static void main(String[] args) throws FileNotFoundException { PrintStream output = System.out; Scanner input = new Scanner(System.in); final int NUMBER = input.nextInt(); final int RANK = input.nextInt(); input.nextLine(); // read the newline ArrayList top = new ArrayList(); for (int n = 0; n < NUMBER; n++) { String line = input.nextLine(); String[] elements = line.split("\\s"); int id = Integer.parseInt(elements[0]); int sum = 0; for (int i = 1; i < elements.length; i++) { sum += Integer.parseInt(elements[i]); } double gpa = sum / (double) (elements.length - 1); Student student = new Student(id, gpa); if (top.size() < RANK) { top.add(student); } else if (student.compareTo(top.get(RANK - 1)) < 0) { top.remove(RANK - 1); top.add(student); } Collections.sort(top); } output.println(top.get(RANK - 1)); } }