結果
| 問題 |
No.1708 Quality of Contest
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-10-18 16:17:50 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,252 ms / 2,000 ms |
| コード長 | 2,302 bytes |
| コンパイル時間 | 2,324 ms |
| コンパイル使用メモリ | 78,032 KB |
| 実行使用メモリ | 61,616 KB |
| 最終ジャッジ日時 | 2024-09-19 11:23:13 |
| 合計ジャッジ時間 | 24,452 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
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, new Comparator<Question>() {
public int compare(Question q1, Question q2) {
if (q1.type == q2.type) {
return q2.value - q1.value;
} else {
return q1.type - q2.type;
}
}
});
int prev = 0;
for (Question q : questions) {
if (q.type != prev) {
prev = q.type;
q.value += x;
}
}
Arrays.sort(questions, new Comparator<Question>() {
public int compare(Question q1, Question q2) {
return q2.value - q1.value;
}
});
long[] sums = new long[n + 1];
for (int i = 0; i < n; i++) {
sums[i + 1] = sums[i] + questions[i].value;
}
long ans = 0;
int k = sc.nextInt();
for (int i = 0; i < k; i++) {
ans += sums[sc.nextInt()];
}
System.out.println(ans);
}
static class Question {
int value;
int type;
public Question(int value, int type) {
this.value = value;
this.type = type;
}
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten