結果

問題 No.2453 Seat Allocation
ユーザー ks2mks2m
提出日時 2023-09-01 23:39:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,065 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 75,716 KB
実行使用メモリ 69,716 KB
最終ジャッジ日時 2023-09-07 15:38:16
合計ジャッジ時間 18,190 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,372 KB
testcase_01 AC 122 ms
56,384 KB
testcase_02 AC 121 ms
56,332 KB
testcase_03 AC 119 ms
55,924 KB
testcase_04 AC 133 ms
55,852 KB
testcase_05 AC 980 ms
68,632 KB
testcase_06 AC 723 ms
64,928 KB
testcase_07 AC 559 ms
67,940 KB
testcase_08 AC 345 ms
60,292 KB
testcase_09 AC 1,033 ms
69,568 KB
testcase_10 AC 1,042 ms
69,716 KB
testcase_11 AC 1,065 ms
69,076 KB
testcase_12 AC 699 ms
64,936 KB
testcase_13 AC 740 ms
65,196 KB
testcase_14 AC 688 ms
65,024 KB
testcase_15 AC 761 ms
65,048 KB
testcase_16 AC 692 ms
64,716 KB
testcase_17 AC 134 ms
56,524 KB
testcase_18 AC 840 ms
66,724 KB
testcase_19 AC 950 ms
66,632 KB
testcase_20 AC 612 ms
61,132 KB
testcase_21 AC 719 ms
61,388 KB
testcase_22 AC 819 ms
65,208 KB
testcase_23 AC 124 ms
56,576 KB
testcase_24 AC 118 ms
55,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int[] b = new int[m + 1];
		for (int i = 0; i < m; i++) {
			b[i] = sc.nextInt();
		}
		sc.close();
		b[m] = 1000000007;

		PriorityQueue<Obj> que = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
			Obj o = new Obj();
			o.a = a[i];
			o.b = b[0];
			o.i = i;
			o.idx = 0;
			que.add(o);
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < m; i++) {
			Obj o = que.poll();
			pw.println(o.i + 1);
			o.idx++;
			o.b = b[o.idx];
			que.add(o);
		}
		pw.flush();
	}

	static class Obj implements Comparable<Obj> {
		int a, b, i, idx;

		@Override
		public int compareTo(Obj o) {
			long v1 = (long) a * o.b;
			long v2 = (long) b * o.a;
			if (v1 != v2) {
				return Long.compare(v2, v1);
			}
			return i - o.i;
		}
	}
}
0