結果

問題 No.1708 Quality of Contest
ユーザー vwxyzvwxyz
提出日時 2021-10-29 22:23:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 988 ms / 2,000 ms
コード長 1,943 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 77,232 KB
最終ジャッジ日時 2024-04-16 15:13:13
合計ジャッジ時間 18,248 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
11,008 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 35 ms
11,008 KB
testcase_03 AC 50 ms
11,776 KB
testcase_04 AC 46 ms
11,904 KB
testcase_05 AC 45 ms
11,776 KB
testcase_06 AC 42 ms
11,520 KB
testcase_07 AC 42 ms
11,648 KB
testcase_08 AC 31 ms
11,136 KB
testcase_09 AC 878 ms
77,232 KB
testcase_10 AC 704 ms
43,352 KB
testcase_11 AC 889 ms
52,836 KB
testcase_12 AC 898 ms
55,332 KB
testcase_13 AC 830 ms
48,300 KB
testcase_14 AC 946 ms
56,384 KB
testcase_15 AC 988 ms
61,356 KB
testcase_16 AC 975 ms
60,924 KB
testcase_17 AC 905 ms
54,376 KB
testcase_18 AC 928 ms
55,456 KB
testcase_19 AC 942 ms
58,556 KB
testcase_20 AC 894 ms
55,608 KB
testcase_21 AC 960 ms
58,272 KB
testcase_22 AC 928 ms
56,696 KB
testcase_23 AC 963 ms
61,028 KB
testcase_24 AC 703 ms
44,112 KB
testcase_25 AC 712 ms
43,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
readline=sys.stdin.readline

class Cumsum:
    def __init__(self,lst,mod=0):
        self.N=len(lst)
        self.mod=mod
        self.cumsum=[0]*(self.N+1)
        self.cumsum[0]=0
        for i in range(1,self.N+1):
            self.cumsum[i]=self.cumsum[i-1]+lst[i-1]
            if self.mod:
                self.cumsum[i]%=self.mod

    def __getitem__(self,i):
        if type(i)==int:
            if 0<=i<self.N:
                a,b=i,i+1
            elif -self.N<=i<0:
                a,b=i+self.N,i+self.N+1
            else:
                raise IndexError('list index out of range')
        else:
            a,b=i.start,i.stop
            if a==None or a<-self.N:
                a=0
            elif self.N<=a:
                a=self.N
            elif a<0:
                a+=self.N
            if b==None or self.N<=b:
                b=self.N
            elif b<-self.N:
                b=0
            elif b<0:
                b+=self.N
        s=self.cumsum[b]-self.cumsum[a]
        if self.mod:
            s%=self.mod
        return s

    def __setitem__(self,i,x):
        if -self.N<=i<0:
            i+=self.N
        elif not 0<=i<self.N:
            raise IndexError('list index out of range')
        self.cumsum[i+1]=self.cumsum[i]+x
        if self.mod:
            self.cumsum[i+1]%=self.mod

    def __str__(self):
        lst=[self.cumsum[i+1]-self.cumsum[i] for i in range(self.N)]
        if self.mod:
            for i in range(self.N):
                lst[i]%=self.mod
        return "["+", ".join(map(str,lst))+"]"

N,M,X=map(int,readline().split())
dct=defaultdict(list)
for i in range(N):
    A,B=map(int,readline().split())
    dct[B].append(A)
lst=[]
for B in dct.keys():
    dct[B].sort()
    dct[B][-1]+=X
    lst+=dct[B]
K=int(readline())
lst.sort(reverse=True)
lst=Cumsum(lst)
ans=0
for c in map(int,readline().split()):
    ans+=lst[:c]
print(ans)
0