結果

問題 No.647 明太子
ユーザー htensai
提出日時 2019-12-26 11:35:50
言語 Java
(openjdk 23)
結果
AC  
実行時間 523 ms / 4,500 ms
コード長 1,709 bytes
コンパイル時間 2,495 ms
コンパイル使用メモリ 77,888 KB
実行使用メモリ 64,268 KB
最終ジャッジ日時 2024-10-03 06:00:22
合計ジャッジ時間 8,334 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] prices = new int[n];
        int[] hots = new int[n];
        for (int i = 0; i < n; i++) {
            prices[i] = sc.nextInt();
            hots[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        Mentai[] mentais = new Mentai[m];
        for (int i = 0; i < m; i++) {
            mentais[i] = new Mentai(i + 1, sc.nextInt(), sc.nextInt());
            for (int j = 0; j < n; j++) {
                mentais[i].buy(prices[j], hots[j]);
            }
        }
        Arrays.sort(mentais);
        int count = mentais[0].count;
        if (count == 0) {
            System.out.println(0);
            return;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < m && mentais[i].count == count; i++) {
            sb.append(mentais[i].idx).append("\n");
        }
        System.out.print(sb);
    }
    
    static class Mentai implements Comparable<Mentai> {
        int idx;
        int price;
        int hot;
        int count;
        public Mentai (int idx, int price, int hot) {
            this.idx = idx;
            this.price = price;
            this.hot = hot;
            count = 0;
        }
        
        public int compareTo(Mentai another) {
            if (count == another.count) {
                return idx - another.idx;
            } else {
                return another.count - count;
            }
        }
        
        public void buy(int p, int h) {
            if (p >= price && h <= hot) {
                count++;
            }
        }
    }
}
0