TSOC '15 Contest 2 #5 - Bebiliths

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Java 1.5s
PyPy 2 2.0s
PyPy 3 2.0s
Memory limit: 100M
Java 50M

Authors:
Problem type

Regroup! Regroup!

The caves have been completely traversed, and Mr. Benum has been located! However, the quest is not over. Swarms of bebiliths, or spider-monsters the size of elephants, are swiftly decimating the ex-convicts! It is up to Max to command the remaining ex-convicts so that they can exterminate the bebilith army. But first, Max has to ensure that the ex-convicts will stay alive!

There are N (1 \le N \le 50\,000) bebiliths in pursuit of one of the groups of ex-convicts. Each bebilith has a speed B (0 \le B \le 10^9), a venom-spitting distance D (0 \le D \le 10^9) and a claw sharpness C (0 \le C \le 10^9) (where the bebilith with the sharpest claw has the highest value of C). Meanwhile, the ex-convicts are running at a uniform speed S (0 \le S \le 10^9).

If two bebiliths have the same speed and are faster or at pace with the ex-convicts, the bebilith with the sharpest claws is more dangerous. However, if two bebiliths have the same speed but are slower than the ex-convicts, the bebilith that spits venom the farthest is more dangerous. Otherwise, if two bebiliths have different speeds, the faster one is more dangerous. Max numbers each bebilith for from 1 to N. If there is a tie between two bebiliths in terms of how dangerous they are, the one that is numbered the lowest is considered more dangerous. Help Max determine what number represents the i^{th} most dangerous bebilith Q (1 \le Q \le N) times!

Input Specification

First line: S

Second line: N

Next N lines: Three space-separated integers B_j D_j C_j on each line. Line j represents the characteristics of the (j-2)^{th} bebilith.

Line N+2: Q

Next Q lines: A single integer i on each line, indicating that the i^{th} most dangerous bebilith's number should be reported back to Max.

Output Specification

Q lines of the i^{th} most dangerous bebilith's number as queried.

Sample Input

5
4
7 29 61
7 42 59
4 1 441221001
3 7 9996999
4
1
2
3
4

Sample Output

1
2
3
4

Explanation

Bebiliths 1 and 2 have the same speed, and both are the fastest. Their speed is greater than Max's speed. Bebilith 1 has sharper claws, so it is the most dangerous, while bebilith 2 is the 2^{nd} most dangerous. Bebilith 3 is faster than bebilith 4, so they are the 3^{rd} and 4^{th} most dangerous, respectively.


Comments


  • 3
    BMP  commented on April 21, 2015, 8:14 p.m.

    I had a really great time reading through your code!


    • 4
      kobortor  commented on April 21, 2015, 10:41 p.m. edited

      return true;


  • 9
    bruce  commented on April 21, 2015, 10:05 a.m.

    For C/C++ submissions, you may get IR error because of the 2M memory limit. Question makers may hate other programming languages except python and java :P