結果

問題 No.1708 Quality of Contest
ユーザー kasuyaSansan
提出日時 2021-10-26 20:01:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,572 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 131,520 KB
最終ジャッジ日時 2024-10-05 21:42:20
合計ジャッジ時間 6,269 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 6 TLE * 1 -- * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,X = map(int, input().split(" "))

questions = []
for i in range(N):
    #print(i,N)
    questions.append(list(map(int, input().split(" "))))

if N > 900000:
    print("read_finish")

K = int(input())
num_answers = list(map(int, input().split(" ")))


def calc_confident(question_list, num_answers, X):
    sum = 0
    for num in num_answers:
        janru = set()
        for i in range(num):
            janru.add(question_list[i][1])
            sum += question_list[i][0]
        sum += len(janru)*X
    return sum

def get_other_j_first(sorted_list, j_set):
    for s in sorted_list:
        if s[1] not in j_set:
            return s
    return None

def get_max(sorted_list, j_set, N, X):
    #sorted_list = sorted(questions, key= lambda x:-x[0])
    if not j_set:
        return sorted_list[0]

    n_j = len(j_set)
    if n_j == N:
        return sorted_list[0]

    max_q = sorted_list[0]
    #other_j_list = [s for s in sorted_list if s[1] not in j_set]
    max_q_j = get_other_j_first(sorted_list, j_set)

    if not max_q_j:
        return max_q

    if max_q == max_q_j:
        return max_q

    dif = max_q[0] - max_q_j[0]
    if dif > X:
        return max_q
    else:
        return max_q_j

print("sort start")
questions = sorted_list = sorted(questions, key= lambda x:-x[0])
now_list = []
j_set = set()
for i in range(len(questions)):
    max_q = get_max(questions, j_set, N,X)

    now_list.append(max_q)
    j_set.add(max_q[1])
    questions.remove(max_q)
    print(i, len(questions))



val = calc_confident(now_list, num_answers, X)
print(val)
0