VPL0_B - Basic Grapes Instinct

no tags 

Dickie is cropping grapes for Christmas! He’s very excited about the traditional grape eating race on December 31th, so he picked every possible raceme of grape in his farm and collect them in a big bucket. Nevertheless, he’s having a serious problems ordering the racemes because there are so many of them!

In order to organize in a efficient way the humongous amount of grape racemes, he decided to build a stemplot out of them. A stemplot goes as follows:

  • The input values for a stemplot are a sequence of numbers and a stem unit.
  • Data is classified based on the stem value, i.e., if a number in the sequence is 403 and the stem unit is 100, then this number is classified in the category 4.
  • For each category, a list of leaf values are render in a single line, sorted in increasing order.
  • Stem values and leaves are separated by a | (pipe character). All | should be vertically aligned.
  • Stem values are sorted in increasing order, omitting empty stems.

Given the sequence s = { 44 46 47 49 63 64 66 68 68 72 72 75 76 81 84 88 106 }, the stemplot generated with a stem unit of 10 is rendered as follow:

       4 | 4 6 7 9
       6 | 3 4 6 8 8
       7 | 2 2 5 6
       8 | 1 4 8
      10 | 6

Dickie is having big trouble rendering these stemplots of grape racemes, can you do the job for him and save the traditional grape race of December 31th?

Input

The first line contains an integer T, which specifies the number of test cases. Then, will follow the descriptions of T test cases.

The first line of each case will contain 2 integers N and U, indicating the size of the sequence and the stem unit. Next N lines will contain a single element of the sequence si.

Output

For each case you should print the string "Scenario #i:" where i is the test case you are evaluating (starting from 1), a new line, and then the corresponding stemplot following the rules stated above. Print a blank line after each stemplot.

Sample

Input
2
17 10
44
46
47
49
63
64
66
68
68
72
72
75
76
81
84
88
106
5 23
1
9
127
23
73

Output
Scenario #1:
 4 | 4 6 7 9
 6 | 3 4 6 8 8
 7 | 2 2 5 6
 8 | 1 4 8
10 | 6

Scenario #2:
0 | 1 9
1 | 0
3 | 4
5 | 12

Subtask 1 - 30%

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 100
  • 1 ≤ U ≤ 100
  • 1 ≤ si ≤ 1,000

Subtask 2 - 70%

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 10,000
  • 1 ≤ U ≤ 1,000
  • 1 ≤ si ≤ 1,000 

hide comments
Ouditchya Sinha: 2013-07-24 15:42:11

Yeah! Fastest Solution again! :)

vikas sharma: 2013-06-24 22:57:47

easy logic...!!! be careful with the output format..:D

raunakrocks: 2013-03-19 22:00:03

AC!!


Added by:Venezuelan Programming League
Date:2012-12-08
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own problem used for VPL0-Contest