#P6619. [省选联考 2020 A/B 卷] 冰火战士
[省选联考 2020 A/B 卷] 冰火战士
Description
A match is about to begin.
Each warrior has two attributes: temperature and energy. There are two factions of warriors. Ice warriors’ skills cool the surroundings and deal freezing damage, so the arena temperature must be no lower than the warrior’s own temperature for them to participate. Fire warriors’ skills heat the surroundings and deal burning damage, so the arena temperature must be no higher than the warrior’s own temperature for them to participate.
Once the arena temperature is fixed, the warriors who can participate on each side form a queue. Ice warriors are sorted by their own temperature from low to high, and fire warriors are sorted by their own temperature from high to low. If temperatures are equal, the warrior with higher energy goes first. First, the first warriors of both sides fight. They consume the same amount of energy; the warrior with less energy will run out of energy and leave the match, while the warrior with remaining energy continues to fight the next warrior on the other side (if both run out of energy, then the next warriors on both sides fight). This repeats until one side’s queue becomes empty, and the match ends.
You need to find the best arena temperature: the maximum temperature value among those that make the total energy consumed by both sides as large as possible.
Now, the match is still in the registration stage, and currently no warriors have registered. Next, you will continuously receive registration messages and withdrawal messages. A registration message contains the faction and the two attributes of the registering warrior, and a withdrawal message contains the index of the registration message to withdraw. Every time the registration status changes (i.e., you receive one message), you must immediately report the current best arena temperature, and the sum of the total energy consumed by both sides at that temperature. If under the current situation the match cannot be held at any temperature (i.e., one side has no warrior that can participate), output Peace.
Input Format
The first line contains an integer , the number of messages.
The next lines are either 1 t x y , and and are both positive integers or 2 k ( is a positive integer):
1 t x y denotes a registration message. If , the registering warrior is an ice warrior; if , the registering warrior is a fire warrior. is the warrior’s own temperature, and is the warrior’s energy.
2 k denotes a withdrawal message, withdrawing the -th message. The withdrawn message is guaranteed to be a registration message. A withdrawn message will not be withdrawn again.
Output Format
Output lines. Each line contains two positive integers separated by one space, representing the current best temperature and the sum of the total energy consumed by both sides at that temperature.
8
1 1 103 150
1 0 100 100
1 1 102 150
1 0 103 300
2 1
1 1 101 100
1 1 104 350
1 0 100 400
Peace
103 200
103 200
103 300
102 200
102 200
104 700
102 1000
Hint
Sample 1 Explanation
For convenience, assume that if the -th message is a registration message, then the corresponding warrior is warrior . In the sample, warriors exist. Since the 5-th message is a withdrawal message, there is no warrior .
The outputs are explained one by one below:
- Only fire warriors exist: warrior . The match cannot be held, output
Peace. - Temperatures can all achieve the maximum consumed energy : warrior vs warrior consumes energy , so the best temperature is .
- Temperatures can all achieve the maximum consumed energy : warrior vs warrior consumes energy , so the best temperature is .
- Temperature can achieve the maximum consumed energy : first, warrior vs warrior consumes energy ; then, warrior vs warrior consumes energy , so the best temperature is .
- From now on, warrior no longer exists. Temperatures can achieve the maximum consumed energy : warrior vs warrior consumes energy , so the best temperature is .
Sample 2
See the additional files icefire2.in and icefire2.ans.
Constraints
of the data: , .
Another of the data: , , there are no withdrawal messages, and the input is non-decreasing in order.
of the data (including the above , same below): , .
of the data: , .
of the data: , , the sum of all does not exceed , and it is guaranteed that there do not exist two warriors with exactly the same .
Translated by ChatGPT 5
京公网安备 11011102002149号