結果
問題 | No.2623 Room Allocation |
ユーザー |
![]() |
提出日時 | 2024-02-19 12:55:59 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 747 ms / 2,000 ms |
コード長 | 2,140 bytes |
コンパイル時間 | 2,492 ms |
コンパイル使用メモリ | 78,988 KB |
実行使用メモリ | 78,504 KB |
最終ジャッジ日時 | 2024-09-29 01:09:12 |
合計ジャッジ時間 | 12,564 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
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();}}}