Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import static java.lang.Integer.parseInt;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.HashMap;
- import java.util.StringTokenizer;
- public class A_Rank_List {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- StringTokenizer tok = new StringTokenizer(reader.readLine());
- int n = parseInt(tok.nextToken()), m = parseInt(tok.nextToken());
- HashMap<String, Integer> map = new HashMap<String, Integer>();
- for (int i = 0; i < n; i++) {
- String str = reader.readLine();
- if (map.containsKey(str)) {
- int x = (int) map.get(str);
- map.put(str, (x + 1));
- } else {
- map.put(str, 1);
- }
- }
- ArrayList<pair> lis = new ArrayList<pair>();
- for (String i : map.keySet()) {
- tok = new StringTokenizer(i);
- int x = map.get(i);
- pair p1 = new pair(parseInt(tok.nextToken()), parseInt(tok.nextToken()));
- for (int j = 0; j < x; j++) {
- lis.add(p1);
- }
- }
- Collections.sort(lis);
- System.out.println(map.get(lis.get(m-1).problem + " " + lis.get(m-1).penlty));
- }
- public static class pair implements Comparable<pair> {
- int problem, penlty;
- public pair(int problem, int penlty) {
- this.problem = problem;
- this.penlty = penlty;
- }
- @Override
- public int compareTo(pair o) {
- if (this.problem < o.problem) {
- return 1;
- } else if (this.problem > o.problem) {
- return -1;
- } else if (this.penlty > o.penlty) {
- return 1;
- } else if (this.penlty < o.penlty) {
- return -1;
- } else {
- return 0;
- }
- }
- }
- }
- /*
- 7 2
- 4 10
- 4 10
- 4 10
- 3 20
- 2 1
- 2 1
- 1 10
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement