結果
問題 | No.1708 Quality of Contest |
ユーザー | tenten |
提出日時 | 2022-09-28 15:34:10 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 910 ms / 2,000 ms |
コード長 | 2,292 bytes |
コンパイル時間 | 2,054 ms |
コンパイル使用メモリ | 74,848 KB |
実行使用メモリ | 69,116 KB |
最終ジャッジ日時 | 2023-08-24 04:26:50 |
合計ジャッジ時間 | 19,406 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
49,932 KB |
testcase_01 | AC | 41 ms
49,780 KB |
testcase_02 | AC | 41 ms
49,736 KB |
testcase_03 | AC | 126 ms
53,500 KB |
testcase_04 | AC | 135 ms
51,724 KB |
testcase_05 | AC | 121 ms
53,696 KB |
testcase_06 | AC | 121 ms
55,452 KB |
testcase_07 | AC | 121 ms
53,376 KB |
testcase_08 | AC | 41 ms
49,800 KB |
testcase_09 | AC | 749 ms
68,236 KB |
testcase_10 | AC | 720 ms
68,260 KB |
testcase_11 | AC | 790 ms
68,284 KB |
testcase_12 | AC | 774 ms
68,424 KB |
testcase_13 | AC | 789 ms
67,636 KB |
testcase_14 | AC | 795 ms
67,420 KB |
testcase_15 | AC | 766 ms
68,144 KB |
testcase_16 | AC | 783 ms
68,064 KB |
testcase_17 | AC | 817 ms
67,232 KB |
testcase_18 | AC | 778 ms
67,680 KB |
testcase_19 | AC | 858 ms
68,856 KB |
testcase_20 | AC | 758 ms
67,544 KB |
testcase_21 | AC | 813 ms
69,112 KB |
testcase_22 | AC | 817 ms
68,364 KB |
testcase_23 | AC | 910 ms
68,256 KB |
testcase_24 | AC | 768 ms
68,180 KB |
testcase_25 | AC | 802 ms
69,116 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); int x = sc.nextInt(); Question[] questions = new Question[n]; for (int i = 0; i < n; i++) { questions[i] = new Question(sc.nextInt(), sc.nextInt()); } Arrays.sort(questions); int prev = 0; long[] values = new long[n]; for (int i = n - 1; i >= 0; i--) { values[i] = questions[i].value; if (questions[i].type != prev) { values[i] += x; prev = questions[i].type; } } Arrays.sort(values); long[] sums = new long[n + 1]; for (int i = 1; i <= n; i++) { sums[i] = sums[i - 1] + values[n - i]; } int k = sc.nextInt(); long ans = 0; for (int i = 0; i < k; i++) { ans += sums[sc.nextInt()]; } System.out.println(ans); } static class Question implements Comparable<Question> { int type; int value; public Question(int value, int type) { this.type = type; this.value = value; } public int compareTo(Question another) { if (type == another.type) { return value - another.value; } else { return type - another.type; } } } } 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 String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }