結果
問題 | No.2453 Seat Allocation |
ユーザー | Asahi |
提出日時 | 2023-09-01 22:52:25 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,445 ms / 2,000 ms |
コード長 | 1,725 bytes |
コンパイル時間 | 2,663 ms |
コンパイル使用メモリ | 75,284 KB |
実行使用メモリ | 76,000 KB |
最終ジャッジ日時 | 2023-09-07 15:37:12 |
合計ジャッジ時間 | 24,355 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 121 ms
56,256 KB |
testcase_01 | AC | 123 ms
55,568 KB |
testcase_02 | AC | 122 ms
56,252 KB |
testcase_03 | AC | 120 ms
55,996 KB |
testcase_04 | AC | 133 ms
56,264 KB |
testcase_05 | AC | 1,331 ms
76,000 KB |
testcase_06 | AC | 1,119 ms
68,940 KB |
testcase_07 | AC | 629 ms
69,136 KB |
testcase_08 | AC | 413 ms
60,580 KB |
testcase_09 | AC | 1,445 ms
73,736 KB |
testcase_10 | AC | 1,377 ms
73,760 KB |
testcase_11 | AC | 1,415 ms
74,104 KB |
testcase_12 | AC | 1,114 ms
68,428 KB |
testcase_13 | AC | 1,151 ms
68,572 KB |
testcase_14 | AC | 1,105 ms
68,384 KB |
testcase_15 | AC | 1,173 ms
69,012 KB |
testcase_16 | AC | 1,119 ms
68,948 KB |
testcase_17 | AC | 136 ms
56,364 KB |
testcase_18 | AC | 1,240 ms
71,452 KB |
testcase_19 | AC | 1,358 ms
73,464 KB |
testcase_20 | AC | 826 ms
65,444 KB |
testcase_21 | AC | 1,036 ms
66,268 KB |
testcase_22 | AC | 1,228 ms
67,860 KB |
testcase_23 | AC | 121 ms
55,860 KB |
testcase_24 | AC | 121 ms
56,140 KB |
ソースコード
import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int[] A = new int[N]; int[] B = new int[M]; for (int i = 0; i < N; i++) { A[i] = sc.nextInt(); } for (int i = 0; i < M; i++) { B[i] = sc.nextInt(); } PriorityQueue<Candidate> pq = new PriorityQueue<>(); for (int i = 0; i < N; i++) { pq.add(new Candidate(A[i], B[0], i + 1, 0)); } for (int i = 0; i < M; i++) { Candidate winner = pq.poll(); System.out.println(winner.party); int nextIndex = winner.index + 1; if (nextIndex < M) { pq.add(new Candidate(A[winner.party - 1], B[nextIndex], winner.party, nextIndex)); } } } static class Candidate implements Comparable<Candidate> { int numerator; int denominator; int party; int index; Candidate(int numerator, int denominator, int party, int index) { this.numerator = numerator; this.denominator = denominator; this.party = party; this.index = index; } @Override public int compareTo(Candidate o) { long x = (long) this.numerator * o.denominator; long y = (long) o.numerator * this.denominator; if (x != y) { return Long.compare(y, x); } return Integer.compare(this.party, o.party); } } }