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

30948번 - Drying Laundry 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 1024 MB122462828.571%

문제

Harry the Beaver runs a hotel and has to wash bed sheets every Sunday night for the next $Q$ weeks until the tourist season ends. On week $j,ドル he has $N$ freshly washed bed sheets that he wants to dry by hanging them on two parallel clotheslines of length $L_j$ each. The sheets can be hung next to each other but must not overlap. Each sheet is $d_i$ units wide and rather long, therefore he will always orient it so that it will take up $d_i$ units of the line when hung to dry. The sheets have different drying times that are not related to their sizes because of different materials. Thus, the $i$-th sheet needs $t^\text{slow}_i$ minutes to dry. However, if it is hung over both lines at the same time, it dries quicker in $t^\text{fast}_i$ minutes, but also takes up space on the other line. To avoid smelly sheets, Harry the Beaver has to start drying all of them immediately after washing, i.e. all sheets have to be hung simultaneously.

Harry the Beaver wants to go to sleep as soon as possible on Sundays, therefore, he asks you to help him determine the minimal required drying time for each week $j,ドル or inform him that it is impossible to finish drying the sheets that week.

입력

The first line contains an integer $N,ドル the number of sheets, and an integer $Q,ドル the number of weeks until the end of the tourist season. The next $N$ lines contain space-separated integers $d_i,ドル $t^\text{fast}_i,ドル and $t^\text{slow}_i,ドル which correspond to the width, the shorter drying time, and the longer drying time of the $i$-th sheet, respectively. The final $Q$ lines the the input contain integers $L_j,ドル $j$-th of which represents the length of the clothesline for week $j$.

출력

Print $Q$ lines, with $j$-th of them containing the minimal required drying time for week $j,ドル or "-1" (without the quotes) if it is impossible to finish drying the sheets that week. If the minimal required drying time for a particular week is longer than the number of minutes in a week, you should still output that drying time rather than -1.

제한

  • 1ドル \leq N \leq 3 \cdot 10^4$
  • 1ドル \leq Q \leq 3 \cdot 10^5$
  • 1ドル \leq d_i \leq 3 \cdot 10^5$ for all 1ドル \leq i \leq N$
  • 1ドル \leq t^\text{fast}_i \leq t^\text{slow}_i \leq 10^9$ for all 1ドル \leq i \leq N$
  • 1ドル \leq L_j \leq 3 \cdot 10^5$ for all 1ドル \leq j \leq Q$

예제 입력 1

3 3
1 2 2
1 1 4
2 3 100
3
1
4

예제 출력 1

4
-1
3

힌트

출처

ICPC > Regionals > Europe > Central European Regional Contest > CERC 2023 D번

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

출처

대학교 대회

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

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