結果

問題 No.2453 Seat Allocation
ユーザー tentententen
提出日時 2023-09-04 13:09:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 633 ms / 2,000 ms
コード長 2,904 bytes
コンパイル時間 5,039 ms
コンパイル使用メモリ 86,512 KB
実行使用メモリ 68,108 KB
最終ジャッジ日時 2023-09-07 15:39:06
合計ジャッジ時間 11,911 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
50,264 KB
testcase_01 AC 45 ms
49,624 KB
testcase_02 AC 44 ms
49,620 KB
testcase_03 AC 44 ms
49,744 KB
testcase_04 AC 46 ms
49,600 KB
testcase_05 AC 466 ms
67,604 KB
testcase_06 AC 294 ms
56,668 KB
testcase_07 AC 238 ms
61,864 KB
testcase_08 AC 145 ms
54,816 KB
testcase_09 AC 633 ms
68,108 KB
testcase_10 AC 548 ms
66,056 KB
testcase_11 AC 552 ms
66,752 KB
testcase_12 AC 276 ms
56,644 KB
testcase_13 AC 300 ms
57,020 KB
testcase_14 AC 279 ms
56,292 KB
testcase_15 AC 339 ms
59,892 KB
testcase_16 AC 282 ms
56,352 KB
testcase_17 AC 46 ms
49,580 KB
testcase_18 AC 426 ms
60,212 KB
testcase_19 AC 462 ms
62,444 KB
testcase_20 AC 299 ms
57,144 KB
testcase_21 AC 339 ms
59,620 KB
testcase_22 AC 390 ms
59,860 KB
testcase_23 AC 44 ms
49,896 KB
testcase_24 AC 45 ms
49,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] parties = new int[n];
        for (int i = 0; i < n; i++) {
            parties[i] = sc.nextInt();
        }
        int[] times = new int[m + 1];
        for (int i = 0; i < m; i++) {
            times[i] = sc.nextInt();
        }
        times[m] = Integer.MAX_VALUE;
        int[] idxes = new int[n];
        PriorityQueue<Result> results = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            results.add(new Result(i, parties[i], times[0]));
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < m; i++) {
            Result x = results.poll();
            sb.append(x.idx + 1).append("\n");
            idxes[x.idx]++;
            results.add(new Result(x.idx, parties[x.idx], times[idxes[x.idx]]));
        }
        System.out.print(sb);
    }
    
    static class Result implements Comparable<Result> {
        int idx;
        long value;
        long base;
        
        public Result(int idx, long value, long base) {
            this.idx = idx;
            this.value = value;
            this.base = base;
        }
        
        public int compareTo(Result another) {
            long comp = value * another.base - another.value * base;
            if (comp == 0) {
                return idx - another.idx;
            } else if (comp < 0) {
                return 1;
            } else {
                return -1;
            }
        }
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0