DMOPC '21 Contest 7 P4 - Rocket Race

View as PDF

Submit solution


Points: 17 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

Tyler is a competitive rocket racer. Unlike in normal foot racing, rocket racers use their own collection of rockets to move instead of their feet. Tyler's collection consists of N single-use rockets. The i-th rocket propels him ai meters forwards, but sends him bi meters backwards immediately after. Of course, rocket technology is constantly evolving, and racers need to update their collection frequently to ensure optimal performance. As Tyler's coach, you must handle Q of the following events, each starting with a value tj:

  • If tj=0 then an integer rj follows, and you must tell Tyler the minimum number of rockets he needs to complete an rj meter race. Note that the race is completed if Tyler reaches or passes the finish line at the rj meter mark at any point. Also, all rockets may only be used in the forward direction (i.e. initially towards the finish line).
  • If tj>0 then two integers xj and yj follow, indicating that Tyler replaces the tj-th rocket with one that propels him xj meters forwards but sends him yj meters backwards immediately after.

Constraints

1N,Q2×105

1ai,bi,rj,xj,yj109

0tjN

Subtask 1 [25%]

1N,Q3×103

Subtask 2 [25%]

tj=0

Subtask 3 [50%]

No additional constraints.

Input Specification

The first line contains an integer N.

The next N lines each contain 2 integers ai and bi.

The next line contains an integer Q.

The next Q lines each contain the description of an event on a single line, as described in the statement.

Output Specification

For each event with tj=0 output the answer on its own line, or 1 if it is impossible to complete that race.

Sample Input

Copy
10
2 1
5 7
4 1
5 4
7 3
9 4
1 6
6 4
5 2
4 5
6
0 15
0 8
6 7 5
0 11
0 8
0 100

Sample Output

Copy
3
1
2
2
-1

Explanation

For the first event, Tyler should use his 5-th, 6-th, and 8-th rockets in that order. This reaches a maximum forward distance of 15 meters, which is just enough to complete the race.

For the fifth event, Tyler should use his 5-th rocket and then his 2-nd rocket. This reaches a maximum forward distance of 9 meters, enough to complete the race.

For the sixth event, it is impossible for Tyler to complete the race regardless of which rockets he chooses to use.


Comments

There are no comments at the moment.