結果

問題 No.1708 Quality of Contest
ユーザー tentententen
提出日時 2021-10-18 16:17:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,345 ms / 2,000 ms
コード長 2,302 bytes
コンパイル時間 2,646 ms
コンパイル使用メモリ 78,596 KB
実行使用メモリ 73,884 KB
最終ジャッジ日時 2023-10-19 15:15:50
合計ジャッジ時間 26,359 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
52,528 KB
testcase_01 AC 54 ms
53,496 KB
testcase_02 AC 52 ms
53,496 KB
testcase_03 AC 142 ms
55,932 KB
testcase_04 AC 147 ms
56,408 KB
testcase_05 AC 145 ms
56,564 KB
testcase_06 AC 136 ms
56,252 KB
testcase_07 AC 141 ms
56,536 KB
testcase_08 AC 55 ms
53,484 KB
testcase_09 AC 784 ms
70,320 KB
testcase_10 AC 753 ms
70,032 KB
testcase_11 AC 1,222 ms
70,336 KB
testcase_12 AC 1,175 ms
73,656 KB
testcase_13 AC 1,216 ms
71,644 KB
testcase_14 AC 1,126 ms
70,380 KB
testcase_15 AC 1,252 ms
73,884 KB
testcase_16 AC 1,243 ms
71,256 KB
testcase_17 AC 1,323 ms
70,984 KB
testcase_18 AC 1,345 ms
70,676 KB
testcase_19 AC 1,208 ms
70,320 KB
testcase_20 AC 1,190 ms
70,248 KB
testcase_21 AC 1,185 ms
71,172 KB
testcase_22 AC 1,153 ms
70,576 KB
testcase_23 AC 1,113 ms
71,328 KB
testcase_24 AC 1,156 ms
70,220 KB
testcase_25 AC 1,101 ms
70,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0