Bitaro the Brave 3

시간 제한2초메모리 제한2048 MB

요약
각 기준값 M에 대해 남은 몬스터의 가중 HP 합이 M 이하가 되도록 처치할 수 있는 최대 난이도를 구한다.
난이도

어려움10점 중 9점

유형
그리디, 정렬, 이분 탐색, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Bitaro, the brave hero, is about to take on the Defense Battle quest to protect the village from monsters. The difficulty of the Defense Battle is represented by an integer between 11 and LL, inclusive, and this value can be chosen at the start of the challenge. In a Defense Battle of difficulty ℓℓ (1≤ℓ≤L1 ≤ ℓ ≤ L), the HP of monsters is multiplied by ℓℓ compared to that at difficulty 11.

The Defense Battle lasts for TT seconds, and NN monsters will appear throughout the battle. Each monster is assigned a unique number from 11 to NN. Time tt (0≤t≤T0 ≤ t ≤ T) refers to the moment tt seconds after the battle starts. Monster ii (1≤i≤N1 ≤ i ≤ N) appears at time S_iS\_i (0≤S_i<T0 ≤ S\_i < T), has strength P_iP\_i, and its HP at difficulty ℓℓ is given by ℓ×H_iℓ \times H\_i.

During the Defense Battle, Bitaro can perform the following action any number of times.

  • Select one of the monsters currently present and attack it, which takes 11 second. The monster’s HP decreases by 11. Once a monster’s HP reaches 00, it is considered defeated and will no longer be attacked.

When time reaches TT, the Defense Battle ends, and the penalty score is computed as follows.

  • Let h_ih\_i be the HP of monster ii (1≤i≤N1 ≤ i ≤ N) immediately after time TT. The penalty score is computed as h_1P_1+h_2P_2+⋯+h_NP_Nh\_1P\_1 + h\_2P\_2 + \cdots + h\_NP\_N.

If the penalty score is less than or equal to a threshold value mm specified by the quest, Bitaro successfully completes the quest.

Since higher difficulties yield better rewards, Bitaro wants to determine the highest difficulty level at which he can complete the quest. However, the threshold value is unknown in advance. Thus, Bitaro decides to determine the highest difficulty level at which he can complete the quest for each of QQ candidate threshold values M_1,M_2,…,M_QM\_1, M\_2, \dots , M\_Q.

Given the information about the Defense Battle and the candidate threshold values, write a program that determines whether the quest can be completed for each threshold value and, if possible, finds the maximum difficulty level at which the quest can be completed.

입력

Read the following data from the standard input.

NN LL TT

S_1S\_1 H_1H\_1 P_1P\_1

S_2S\_2 H_2H\_2 P_2P\_2

⋮\vdots

S_NS\_N H_NH\_N P_NP\_N

QQ

M_1M\_1

M_2M\_2

⋮\vdots

M_QM\_Q

출력

Write QQ lines to the standard output. In the jj-th line (1≤j≤Q1 ≤ j ≤ Q), output the maximum difficulty level at which the quest can be completed when m=M_jm = M\_j. If the quest cannot be completed at any difficulty level, output 0 instead.

제한

  • 1≤N≤6,0001 ≤ N ≤ 6\\, 000.
  • 1≤L≤10,000,0001 ≤ L ≤ 10\\, 000\\, 000.
  • 1≤T≤10181 ≤ T ≤ 10^{18}.
  • 0≤S_i<T0 ≤ S\_i < T (1≤i≤N1 ≤ i ≤ N).
  • 1≤H_i1 ≤ H\_i (1≤i≤N1 ≤ i ≤ N).
  • 1≤P_i1 ≤ P\_i (1≤i≤N1 ≤ i ≤ N).
  • H_1P_1+H_2P_2+⋯+H_NP_N≤1011H\_1P\_1 + H\_2P\_2 + \cdots + H\_NP\_N ≤ 10^{11}.
  • 1≤Q≤1,000,0001 ≤ Q ≤ 1\\, 000\\, 000.
  • 0≤M_j≤10180 ≤ M\_j ≤ 10^{18} (1≤j≤Q1 ≤ j ≤ Q).
  • M_1<M_2<⋯<M_QM\_1 < M\_2 < \cdots < M\_Q.
  • Given values are all integers.

예제5

  1. 예제 1

    입력
    2 2 10
    0 9 2
    8 5 1
    3
    0
    20
    40
    
    예상 출력
    0
    1
    2
    
  2. 예제 2

    입력
    3 1 100000000000
    60000000000 30000000000 1
    30000000000 45000000000 1
    10000000000 10000000000 1
    1
    0
    
    예상 출력
    0
    
  3. 예제 3

    입력
    3 10000000 100000000
    60000000 4 1
    30000000 6 1
    0 2 1
    1
    0
    
    예상 출력
    7000000
    
  4. 예제 4

    입력
    5 20 100
    0 3 1
    20 2 2
    40 1 3
    60 4 4
    80 2 5
    11
    0
    50
    100
    150
    200
    250
    300
    350
    400
    450
    500
    
    예상 출력
    6
    8
    10
    12
    13
    15
    16
    18
    19
    20
    20
    
  5. 예제 5

    입력
    15 10000000 1000000000000
    160278118759 43084 33592
    442653603914 19490 23090
    824219815410 50858 89563
    502303340628 56629 45080
    495062829942 87342 28821
    234536700105 45384 34328
    396080693809 78081 50812
    734374391045 40873 92012
    122606844331 25451 30426
    204076581972 58431 13989
    495156368673 54276 41670
    812963939390 27614 50228
    405067019838 96324 18477
    464546304875 67562 45956
    528559327980 41759 15546
    10
    216000000000000
    1728000000000000
    5832000000000000
    13824000000000000
    27000000000000000
    46656000000000000
    74088000000000000
    110592000000000000
    157464000000000000
    216000000000000000
    
    예상 출력
    995176
    1135557
    1431775
    1824183
    2359362
    3059523
    3942014
    5106209
    6594716
    8448125