Logo
(追記) (追記ここまで)

18502번 - Bad Doctor 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB78322843.750%

문제

Alex got sick. He went to a clinic and visited n doctors. The i-th doctor said that starting with the day li and ending with the day ri Alex must take ki medicines: a1, a2, . . ., aki, one pill a day of each. Medicines are numbered from 1 to m.

Of course, if several doctors tell Alex to take the same medicine at the same day, he will take only one pill of this medicine that day. At least, this is how people act in real life.

One pill of the medicine j costs cj roubles. But Alex has a doubt: the rumors say that one of the doctors in the clinic is really bad. He doesn’t know which doctor is bad, but he decided to ignore this doctor’s prescription.

Your task is to find n numbers ti: know how much money Alex will spend on the pills if the i-th doctor is bad.

입력

The first line contains two integers n and m: the number of doctors and the number of medicines (1 ≤ n ≤ 500 000, 1 ≤ m ≤ 500 000).

The second line contains m integers cj: the cost of one pill of the j-th medicine (1 ≤ cj ≤ 1 000 000).

Each of the next n lines describes doctors. The i-th of them starts with three integers li, ri, ki: the start and end days in the i-th doctor’s prescription and the number of medicines he told Alex to take (1 ≤ li ≤ ri ≤ 1 000 000, 1 ≤ ki ≤ m). Then follow ki distinct integers a1, a2, . . ., aki, each from 1 to m: the medicines in the prescription.

The sum of all ki in the input doesn’t exceed 1 000 000.

출력

Output n integers t1, t2, . . ., tn: how much money Alex will spend on the pills if he ignores the i-th doctor’s prescription.

제한

예제 입력 1

5 4
1000 100 10 1
3 4 2 2 3
4 8 3 1 2 4
6 7 2 3 4
8 9 2 1 4
2 6 3 1 2 3

예제 출력 1

8766 7564 8756 7765 6646

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2020 > Day 4: Yandex Cup 2020 B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /