結果
問題 | No.647 明太子 |
ユーザー | denderaKawazu |
提出日時 | 2018-02-09 22:59:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 545 ms / 4,500 ms |
コード長 | 3,081 bytes |
コンパイル時間 | 2,522 ms |
コンパイル使用メモリ | 89,840 KB |
実行使用メモリ | 49,012 KB |
最終ジャッジ日時 | 2024-06-27 02:34:39 |
合計ジャッジ時間 | 9,936 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 134 ms
41,364 KB |
testcase_01 | AC | 132 ms
41,436 KB |
testcase_02 | AC | 134 ms
41,384 KB |
testcase_03 | AC | 137 ms
41,268 KB |
testcase_04 | AC | 138 ms
41,720 KB |
testcase_05 | AC | 135 ms
40,752 KB |
testcase_06 | AC | 129 ms
41,392 KB |
testcase_07 | AC | 153 ms
41,800 KB |
testcase_08 | AC | 153 ms
41,796 KB |
testcase_09 | AC | 231 ms
44,416 KB |
testcase_10 | AC | 251 ms
44,684 KB |
testcase_11 | AC | 213 ms
43,192 KB |
testcase_12 | AC | 237 ms
45,304 KB |
testcase_13 | AC | 270 ms
46,896 KB |
testcase_14 | AC | 502 ms
49,012 KB |
testcase_15 | AC | 297 ms
47,820 KB |
testcase_16 | AC | 233 ms
44,452 KB |
testcase_17 | AC | 524 ms
48,804 KB |
testcase_18 | AC | 545 ms
48,896 KB |
testcase_19 | AC | 443 ms
48,960 KB |
testcase_20 | AC | 454 ms
48,916 KB |
testcase_21 | AC | 328 ms
47,972 KB |
testcase_22 | AC | 511 ms
48,644 KB |
testcase_23 | AC | 202 ms
43,192 KB |
ソースコード
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; } } } }