Landing Raid
Time limit6sMemory limit1024 MB
Choose k of n soldiers so the chosen subsequence of permutation a has the fewest inversions, then count the optimal choices for each k.
- Level
Hard9 of 10
- Topics
- Divide and conquer, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Statement
For many years Bitocja has regularly raided Bajtocja, stealing its natural and intellectual resources. This time the Bajtocjans will strike first against the treacherous Bitocjan people. The first step of a carefully planned strategy is a landing on the beach of Bitobajtan.
The operation must be discreet, so a squad of exactly members of the elite unit Bajtogrom will be sent to the beach. The unit currently has soldiers, numbered from 1 to . Soldier has hand-to-hand combat level and ranged combat level . The sequence is a permutation of the numbers from 1 to . A higher level means the soldier is more advanced in that discipline.
In a well-run special unit, everyone must know whom to obey and whom they may give orders to. If two soldiers and are both sent on the mission, with and , friction may occur between them. They will quarrel over who outranks whom in Bajtogrom.
When choosing soldiers for the landing, the squad must be chosen so that the number of pairs that may cause friction is as small as possible. Find that minimum number of pairs. Also find the number of ways to choose a squad of soldiers that reaches this minimum. Do this for every from 1 to .
Input
The first line contains one integer (), the number of soldiers in Bajtogrom.
The second line contains integers (, for ), where is the ranged combat level of soldier .
Output
Print lines, each with two integers. On line , print the minimum number of pairs that may cause friction when exactly soldiers are sent, followed by the number of ways to reach that minimum.
Hint
For , no pair of soldiers can cause friction, and the single soldier can be chosen in 5 ways.
For , one of the pairs (2, 4), (3, 4), or (3, 5) must be chosen, so that no friction occurs.
For , sending (2, 3, 4) or (3, 4, 5) leaves only one pair that may cause friction.
For , it is best to send everyone except the first soldier. The first soldier is the weakest in hand-to-hand combat because of his index, but has the highest ranged level, , so he may cause friction with every other soldier.
For , seven pairs may cause friction.