Marathon
InterviewTime limit0.2sMemory limit256 MB
Groups at distinct coordinates move right at speed 100/size and merge on contact; simulate until stable and report final sizes left to right.
- Level
Medium6 of 10
- Topics
- Stack, Simulation, Sorting, Implementation
- Solved
- No attempts yet
Problem
You have started running long distances. Treat the road the runners use as a straight infinite line. At one moment the runners split into groups. Group holds people and stands at coordinate . A group of people runs toward growing coordinates at speed , so a larger group is slower.
When a group reaches the group in front of it, the two merge at once into one group. The merged group holds all of their people, and its speed changes to match the new size. Three or more groups can merge at the same instant.
The road is infinite, so from some moment on no merge is possible any more. Report how many groups are left and how many people each of them holds.
Input
The first line has an integer (). Each of the next lines has the size and the coordinate of one group (, and is a real number written with at most three digits after the decimal point with ). All coordinates are different, and the groups come in arbitrary order.
Output
Print the number of remaining groups on the first line. On the second line print their sizes in non-increasing order, separated by single spaces. That order is also the order of the groups along the road, from the smallest final coordinate to the largest, because once no merge is left, a group is never smaller than the group in front of it.