A:Balanced Rating Changes
้ข็ฎ๏ผ
Another Codeforces Round has just finished! It has gathered ๐ participants, and according to the results, the expected rating change of participant ๐ is ๐๐. These rating changes are perfectly balanced โ their sum is equal to 0.
Unfortunately, due to minor technical glitches, the round is declared semi-rated. It means that all rating changes must be divided by two.
There are two conditions though:
For each participant ๐, their modified rating change ๐๐ must be integer, and as close to ๐๐/2 as possible. It means that either ๐๐=โ๐๐/2โ or ๐๐=โ๐๐/2โ. In particular, if ๐๐ is even, ๐๐=๐๐2. Here โ๐ฅโ denotes rounding down to the largest integer not greater than ๐ฅ, and โ๐ฅโ denotes rounding up to the smallest integer not smaller than ๐ฅ.
The modified rating changes must be perfectly balanced โ their sum must be equal to 0.
Can you help with that?
Input
The first line contains a single integer ๐ (2โค๐โค13845), denoting the number of participants.
Each of the next ๐ lines contains a single integer ๐๐ (โ336โค๐๐โค1164), denoting the rating change of the ๐-th participant.
The sum of all ๐๐ is equal to 0.
Output
Output ๐ integers ๐๐, each denoting the modified rating change of the ๐-th participant in order of input.
For any ๐, it must be true that either ๐๐=โ๐๐/2โ or ๐๐=โ๐๐/2โ. The sum of all ๐๐ must be equal to 0.
If there are multiple solutions, print any. We can show that a solution exists for any valid input.
Examples
input
1 | 3 |
output
1 | 5 |
input
1 | 7 |
output
1 | -3 |
้ข่งฃ๏ผ
็ป่ฎกๆญฃๆฐไธ่ดๆฐ็ๅฅๆฐไนๅทฎ๏ผ็ถๅๅจ่พๅบๆถ่ฟ่กๅค็ๅณๅฏใ
ไปฃ็ ๏ผ
1 | #include<stdio.h> |
B๏ผ Balanced Tunnel
้ข็ฎ๏ผ
Consider a tunnel on a one-way road. During a particular day, ๐ cars numbered from 1 to ๐ entered and exited the tunnel exactly once. All the cars passed through the tunnel at constant speeds.
A traffic enforcement camera is mounted at the tunnel entrance. Another traffic enforcement camera is mounted at the tunnel exit. Perfectly balanced.
Thanks to the cameras, the order in which the cars entered and exited the tunnel is known. No two cars entered or exited at the same time.
Traffic regulations prohibit overtaking inside the tunnel. If car ๐ overtakes any other car ๐ inside the tunnel, car ๐ must be fined. However, each car can be fined at most once.
Formally, letโs say that car ๐ definitely overtook car ๐ if car ๐ entered the tunnel later than car ๐ and exited the tunnel earlier than car ๐. Then, car ๐ must be fined if and only if it definitely overtook at least one other car.
Find the number of cars that must be fined.
Input
The first line contains a single integer ๐ (2โค๐โค105), denoting the number of cars.
The second line contains ๐ integers ๐1,๐2,โฆ,๐๐ (1โค๐๐โค๐), denoting the ids of cars in order of entering the tunnel. All ๐๐ are pairwise distinct.
The third line contains ๐ integers ๐1,๐2,โฆ,๐๐ (1โค๐๐โค๐), denoting the ids of cars in order of exiting the tunnel. All ๐๐ are pairwise distinct.
Output
Output the number of cars to be fined.
Examples
input
1 | 5 |
output
1 | 2 |
input
1 | 7 |
output
1 | 6 |
input
1 | 2 |
output
1 | 0 |
้ข่งฃ๏ผ
ๆญคไปฃ็ ็จ็ๅฝๅนถๆๅบ่ฟ่กๅค็๏ผๅคๆๅบฆไธบnlogn ๆๅคๆๅบฆไธบn็ๆนๆณ๏ผไปฅๅ่กฅไธใ่ฟ่กๅฝๅนถๆๅธๆถ๏ผๅบ็ฐ้ๅบๆถ๏ผๅฐๅๅคง็ๆฐๅญ่ฟ่ก่ฎฐๅฝๅฐฑๅฏใ
ไปฃ็ :
1 | #include<stdio.h> |
C๏ผBalanced Removals (Easier)
้ข็ฎ๏ผ
This is an easier version of the problem. In this version, ๐โค2000.
There are ๐ distinct points in three-dimensional space numbered from 1 to ๐. The ๐-th point has coordinates (๐ฅ๐,๐ฆ๐,๐ง๐). The number of points ๐ is even.
Youโd like to remove all ๐ points using a sequence of ๐2 snaps. In one snap, you can remove any two points ๐ and ๐ that have not been removed yet and form a perfectly balanced pair. A pair of points ๐ and ๐ is perfectly balanced if no other point ๐ (that has not been removed yet) lies within the axis-aligned minimum bounding box of points ๐ and ๐.
Formally, point ๐ lies within the axis-aligned minimum bounding box of points ๐ and ๐ if and only if min(๐ฅ๐,๐ฅ๐)โค๐ฅ๐โคmax(๐ฅ๐,๐ฅ๐), min(๐ฆ๐,๐ฆ๐)โค๐ฆ๐โคmax(๐ฆ๐,๐ฆ๐), and min(๐ง๐,๐ง๐)โค๐ง๐โคmax(๐ง๐,๐ง๐). Note that the bounding box might be degenerate.
Find a way to remove all points in ๐2 snaps.
Input
The first line contains a single integer ๐ (2โค๐โค2000; ๐ is even), denoting the number of points.
Each of the next ๐ lines contains three integers ๐ฅ๐, ๐ฆ๐, ๐ง๐ (โ108โค๐ฅ๐,๐ฆ๐,๐ง๐โค108), denoting the coordinates of the ๐-th point.
No two points coincide.
Output
Output ๐2 pairs of integers ๐๐,๐๐ (1โค๐๐,๐๐โค๐), denoting the indices of points removed on snap ๐. Every integer between 1 and ๐, inclusive, must appear in your output exactly once.
We can show that it is always possible to remove all points. If there are many solutions, output any of them.
Examples
input
1 | 6 |
output
1 | 3 6 |
input
1 | 8 |
output
1 | 4 5 |
้ข่งฃ๏ผ
ๆ็บฟ้ขไฝ็้กบๅบ่ฟ่กไพๆฌกๅ ้คใๅณๆxyz้กบๅบ่ฟ่กๆๅบ๏ผๅ ๅ ้คxy็ธๅ็๏ผๅๅ ้คx็ธๅ็๏ผ็ถๅๅไพๆฌกๅ ้ค๏ผๆณจๆๆฏๆฌกๅ ้คๅ้ฝ่ฆๆๅบไธๆฌกใ
ไปฃ็ ๏ผ
1 | #include<stdio.h> |