結果

問題 No.2453 Seat Allocation
ユーザー ks2m
提出日時 2023-09-01 23:39:30
言語 Java
(openjdk 23)
結果
AC  
実行時間 964 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 4,307 ms
コンパイル使用メモリ 81,044 KB
実行使用メモリ 64,932 KB
最終ジャッジ日時 2025-06-20 01:48:13
合計ジャッジ時間 17,218 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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