2016北京网络赛 hihocoder 1391 Countries 树状数组
描述
There are two antagonistic countries, country A and country B. They are in a war, and keep launching missiles towards each other.
It is known that country A will launch N missiles. The i-th missile will be launched at time Tai. It flies uniformly and take time Taci from one country to the other. Its damage capability is Dai.
It is known that country B will launch M missiles. The i-th missile will be launched at time Tbi.
It flies uniformly and takes time Tbci from one country to the other. Its damage capability is Dbi.
Both of the countries can activate their own defending system.
The defending system of country A can last for time TA, while The defending system of country B can last for time TB.
When the defending system is activated, all missiles reaching the country will turn around and fly back at the same speed as they come.
At other time, the missiles reaching the country will do damages to the country.
(Note that the defending system is still considered active at the exact moment it fails)
Country B will activate its defending system at time X.
When is the best time for country A to activate its defending system? Please calculate the minimal damage country A will suffer.
输入
There are no more than 50 test cases.
For each test case:
The first line contains two integers TA and TB, indicating the lasting time of the defending system of two countries.
The second line contains one integer X, indicating the time that country B will active its defending system.
The third line contains two integers N and M, indicating the number of missiles country A and country B will launch.
Then N lines follow. Each line contains three integers Tai, Taci and Dai, indicating the launching time, flying time and damage capability of the i-th missiles country A launches.
Then M lines follow. Each line contains three integers Tbi, Tbci and Dbi, indicating the launching time, flying time and damage capability of the i-th missiles country B launches.
0 <= TA, TB, X, Tai, Tbi<= 100000000
1 <= Taci, Tbci <= 100000000
0 <= N, M <= 10000
1 <= Dai, Dbi <= 10000
输出
For each test case, output the minimal damage country A will suffer.
提示
In the first case, country A should active its defending system at time 3.
Time 1: the missile is launched by country A.
Time 2: the missile reaches country B, and country B actives its defending system, then the missile turns around.
Time 3: the missile reaches country A, and country A actives its defending system, then the missile turn around.
Time 4: the missile reaches country B and turns around.
Time 5: the missile reaches country A and turns around.
Time 6: the missile reaches country B, causes damages to country B.
- 样例输入
-
2 2 2 1 0 1 1 10 4 5 3 2 2 1 2 10 1 5 7 1 3 2 0 4 8
- 样例输出
-
0 17