結果

問題 No.647 明太子
ユーザー htensaihtensai
提出日時 2019-12-26 11:35:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 563 ms / 4,500 ms
コード長 1,709 bytes
コンパイル時間 2,401 ms
コンパイル使用メモリ 77,676 KB
実行使用メモリ 64,564 KB
最終ジャッジ日時 2024-04-14 08:56:48
合計ジャッジ時間 9,882 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
54,004 KB
testcase_01 AC 135 ms
53,856 KB
testcase_02 AC 134 ms
54,016 KB
testcase_03 AC 134 ms
54,100 KB
testcase_04 AC 138 ms
54,264 KB
testcase_05 AC 138 ms
54,264 KB
testcase_06 AC 138 ms
53,964 KB
testcase_07 AC 148 ms
54,244 KB
testcase_08 AC 146 ms
54,624 KB
testcase_09 AC 207 ms
56,856 KB
testcase_10 AC 218 ms
56,760 KB
testcase_11 AC 194 ms
54,760 KB
testcase_12 AC 211 ms
57,016 KB
testcase_13 AC 232 ms
56,992 KB
testcase_14 AC 469 ms
59,220 KB
testcase_15 AC 253 ms
58,188 KB
testcase_16 AC 215 ms
56,884 KB
testcase_17 AC 508 ms
59,720 KB
testcase_18 AC 523 ms
60,076 KB
testcase_19 AC 382 ms
58,940 KB
testcase_20 AC 355 ms
59,256 KB
testcase_21 AC 260 ms
58,656 KB
testcase_22 AC 563 ms
64,564 KB
testcase_23 AC 195 ms
54,420 KB
権限があれば一括ダウンロードができます

ソースコード

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