結果

問題 No.647 明太子
ユーザー denderaKawazudenderaKawazu
提出日時 2018-02-09 22:59:09
言語 Java19
(openjdk 21)
結果
AC  
実行時間 529 ms / 4,500 ms
コード長 3,081 bytes
コンパイル時間 2,564 ms
コンパイル使用メモリ 82,996 KB
実行使用メモリ 62,804 KB
最終ジャッジ日時 2023-09-09 09:26:13
合計ジャッジ時間 10,016 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
55,552 KB
testcase_01 AC 134 ms
55,616 KB
testcase_02 AC 133 ms
56,308 KB
testcase_03 AC 132 ms
55,700 KB
testcase_04 AC 137 ms
55,604 KB
testcase_05 AC 137 ms
55,888 KB
testcase_06 AC 136 ms
53,740 KB
testcase_07 AC 153 ms
56,244 KB
testcase_08 AC 153 ms
56,004 KB
testcase_09 AC 218 ms
59,156 KB
testcase_10 AC 250 ms
60,348 KB
testcase_11 AC 207 ms
56,720 KB
testcase_12 AC 242 ms
59,660 KB
testcase_13 AC 267 ms
60,244 KB
testcase_14 AC 464 ms
60,328 KB
testcase_15 AC 304 ms
59,480 KB
testcase_16 AC 244 ms
57,232 KB
testcase_17 AC 488 ms
60,836 KB
testcase_18 AC 529 ms
60,392 KB
testcase_19 AC 380 ms
60,336 KB
testcase_20 AC 380 ms
60,352 KB
testcase_21 AC 302 ms
61,136 KB
testcase_22 AC 498 ms
62,804 KB
testcase_23 AC 204 ms
57,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<Integer> p = new ArrayList<>();
            ArrayList<Integer> h = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int maxP = in.nextInt();
                int minH = in.nextInt();
                p.add(maxP);
                h.add(minH);
            }

            int m = in.nextInt();
            ArrayList<TaskB.Mentaiko> ms = new ArrayList<>();
            for (int i = 0; i < m; i++) {
                int cp = in.nextInt();
                int ch = in.nextInt();
                int id = i + 1;
                ms.add(new TaskB.Mentaiko(cp, ch, id));
            }

            for (int i = 0; i < n; i++) {
                int cp = p.get(i);
                int ch = h.get(i);
                for (TaskB.Mentaiko cm : ms) {
                    if (cp >= cm.getPrice() && ch <= cm.getHot()) cm.setSold(cm.getSold() + 1);
                }
            }

            Comparator<TaskB.Mentaiko> soldNumComparator = Comparator.comparing(TaskB.Mentaiko::getSold);

            ms.sort(soldNumComparator.reversed());

            int max = ms.get(0).getSold();
            if (max == 0) {
                out.println(0);
                return;
            }

            ArrayList<Integer> best = new ArrayList<>();
            for (TaskB.Mentaiko cm : ms) {
                if (cm.getSold() != max) break;
                best.add(cm.getId());
            }

            Collections.sort(best);

            for (int i : best) out.println(i);
        }

        static class Mentaiko {
            private int price;
            private int hot;
            private int sold;
            private int id;

            protected Mentaiko(int price, int hot, int id) {
                this.price = price;
                this.hot = hot;
                this.id = id;
                this.sold = 0;
            }

            public void setSold(int sold) {
                this.sold = sold;
            }

            public int getSold() {
                return sold;
            }

            public int getId() {
                return id;
            }

            public int getHot() {
                return hot;
            }

            public int getPrice() {
                return price;
            }

        }

    }
}

0