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
nadstratosfer: 2019-12-31 05:22:20

Solved in time for las campanadas! 16 lines in Python. Might try again in C later on if in masochistic mood..

Print blankline after each case, but not after the "Scenario" line, eg. as the sample shows, not as the statement says.

Nandu: 2014-12-27 15:21:37

Got AC in 1st Go !! :D

ROHIT RAJ: 2014-12-27 11:21:06

so many WA's coz of a newline at the end.. :| be careful!

Diksha Jaiswal: 2014-12-23 16:07:46

AC in 1 go :D

***: 2013-12-09 13:04:27

a silly mistake causes me many wa's !!!

hiddenman: 2013-09-11 21:00:57

easy 1.....take care of output format..... :)

Raman Shukla: 2013-08-19 05:36:50

Poor problem description... The stem values may not be sorted... Got so many WA's due to this...

napster: 2013-08-10 12:31:59

Finallly!!:got AC after 6 WA due to silly mistake.:D

Last edit: 2013-08-10 12:32:46
mystique_blue: 2013-07-31 18:07:16

I did not know why i got Wa's and I did not know why I ultimately got the AC..... I hate output design oriented problems.. :|

napster: 2013-07-27 07:16:46

@Venezuelan Programming League:
plzz see my code,why i'm getting WA after 6 test cases.....my submission id is--->9729279

Last edit: 2013-07-27 07:17:15

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