Robots
Time limit2sMemory limit1024 MB
Given N robots and N antennas on a line, activate antennas one at a time so each pulls its nearest remaining robot; minimize total distance moved and output an order.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Sorting, Two pointers
- Solved
- No attempts yet
Problem
There are robots numbered from through and antennas numbered from through on a straight line. The coordinate of robot is and the coordinate of antenna is . All coordinates are distinct.
Currently all antennas are inactive. You are going to activate them one by one. When you activate an antenna, the nearest robot moves to that antenna and explodes along with it. If two robots are equally close, only the left one moves.
Find an order to activate the antennas so that the total distance the robots move is minimum.
Input
Input is given from Standard Input in the following format:
Output
Print the answer in the following format:
Here, is the minimum total distance, and is the index of the antenna you activate in the -th step.
If there are multiple solutions, you can print any of them.
Constraints
- are all distinct.
- All values in input are integers.