結果

問題 No.2623 Room Allocation
ユーザー tentententen
提出日時 2024-02-19 12:55:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 691 ms / 2,000 ms
コード長 2,140 bytes
コンパイル時間 6,525 ms
コンパイル使用メモリ 78,340 KB
実行使用メモリ 82,072 KB
最終ジャッジ日時 2024-02-19 12:56:17
合計ジャッジ時間 16,666 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
53,980 KB
testcase_01 AC 48 ms
53,988 KB
testcase_02 AC 49 ms
53,980 KB
testcase_03 AC 48 ms
53,976 KB
testcase_04 AC 47 ms
53,980 KB
testcase_05 AC 47 ms
53,988 KB
testcase_06 AC 281 ms
64,428 KB
testcase_07 AC 275 ms
64,432 KB
testcase_08 AC 269 ms
64,440 KB
testcase_09 AC 266 ms
64,420 KB
testcase_10 AC 123 ms
67,900 KB
testcase_11 AC 111 ms
67,792 KB
testcase_12 AC 72 ms
58,104 KB
testcase_13 AC 94 ms
60,024 KB
testcase_14 AC 488 ms
82,072 KB
testcase_15 AC 303 ms
62,628 KB
testcase_16 AC 195 ms
58,768 KB
testcase_17 AC 117 ms
55,004 KB
testcase_18 AC 299 ms
62,388 KB
testcase_19 AC 282 ms
62,604 KB
testcase_20 AC 282 ms
62,356 KB
testcase_21 AC 312 ms
62,344 KB
testcase_22 AC 273 ms
62,332 KB
testcase_23 AC 205 ms
60,664 KB
testcase_24 AC 301 ms
62,432 KB
testcase_25 AC 262 ms
62,376 KB
testcase_26 AC 152 ms
58,276 KB
testcase_27 AC 685 ms
74,148 KB
testcase_28 AC 315 ms
69,160 KB
testcase_29 AC 275 ms
67,772 KB
testcase_30 AC 691 ms
74,260 KB
testcase_31 AC 148 ms
61,356 KB
testcase_32 AC 226 ms
68,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static List<Set<Integer>> graph;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        Group[] groups = new Group[x + y];
        for (int i = 0; i < x + y; i++) {
            groups[i] = new Group();
        }
        for (int i = 0; i < n; i++) {
            int idx = i % (x + y);
            int count = sc.nextInt();
            char color = sc.next().charAt(0);
            if (color == 'A') {
                groups[idx].a += count;
            } else {
                groups[idx].b += count;
            }
        }
        Arrays.sort(groups);
        long ans = 0;
        for (int i = 0; i < x + y; i++) {
            if (i < x) {
                ans += groups[i].a;
            } else {
                ans += groups[i].b;
            }
        }
        System.out.println(ans);
    }
    
    static class Group implements Comparable<Group> {
        long a;
        long b;
        
        public int compareTo(Group another) {
            return Long.compare(b - a, another.b - another.a);
        }
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0