Physics
Time limit1sMemory limit1024 MB
Given the max and min of two piecewise linear velocity graphs over time T, restore both graphs, each covering the same distance.
- Level
Hard8 of 10
- Topics
- Implementation, Two pointers, Brute force
- Solved
- No attempts yet
Statement
Android Vasya reads the book Amusing physics for the smallest children. Recently he read a chapter about uniformly accelerated motion and decided to set up some experiments. For this purpose, Vasya made a mechanical turtle that can be given a different acceleration by remote control.
Vasya launched his turtle into the lobby and changed its acceleration several times. After plotting the piecewise linear velocity function , he repeated the experiment. This time he got a piecewise linear continuous function and plotted its graph too.
Before the third try, Vasya realized that plotting and on the same graph was a mistake. Now it is unclear which segments belong to which function. Help Vasya restore the graphs. Both experiments lasted the same time , and in both runs the turtle covered the same distance, which is the length of the lobby.
Input
The first line contains an integer , the duration of each experiment (). Then the description of the functions and follows. The second line contains an integer , the number of kink points of . The next lines contain pairs of integers and , the kink points of (, ). No three consecutive kink points lie on the same straight line. The following lines describe in the same format. For any , , and holds at no more than 30 points (in particular, the graphs share no common segments). Each function has between 2 and 100000 kink points.
Output
Output the functions and in the same format as and . No three consecutive kink points may lie on the same straight line. All numbers in the output must be integers. If there are several solutions, print any of them. At least one solution is guaranteed to exist.