Under my umbrella.

SKII

Less is more.

洛谷 P1068 分数线划定(JAVA)

洛谷 P1068 分数线划定

package Algorithm;

import java.util.*;

class Member implements Comparable {
    int k, s;

    @Override
    public int compareTo(Object o) {
        Member t = (Member)o;
        return t.s - this.s == 0 ? this.k - t.k : t.s - this.s;
    }
}
public class Department1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(), m = scan.nextInt();
        int line = (int)(m * 1.5);
        ArrayList<Member> li = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            int k = scan.nextInt(), s = scan.nextInt();
            Member me = new Member();
            me.k = k; me.s = s; li.add(me);
        }
        Collections.sort(li);
        int cnt = 0;
        for(int i = line; i < li.size(); i++) {
            if(li.get(i).s == li.get(line-1).s) {
                cnt++;
            } else {
                break;
            }
        }
        System.out.println(li.get(line-1).s + " " + (line+cnt));
        for(int i = 0; i < line+cnt; i++) {
            System.out.println(li.get(i).k + " " + li.get(i).s);
        }
    }
}
posted @ 2020-02-20 14:21  NLYang  阅读(212)  评论(0编辑  收藏  举报