# Manasa and Stones

# Manasa and Stones

+ 39 comments Here is the gist: Compute the difference between a and b, start a while loop at lowest possible answer; a * n-1. Then add difference to this value & string. Then iterate until value = maxium output of b * n-1.

Here is is in C#:

`using System; using System.Collections.Generic; using System.IO; using System.Text; class Solution { static void Main(String[] args) { var cases = Convert.ToInt32(Console.ReadLine()); for(var ii = 0; ii < cases; ii++){ var stones = Convert.ToInt32(Console.ReadLine()) - 1; var one = Convert.ToInt32(Console.ReadLine()); var two = Convert.ToInt32(Console.ReadLine()); var a = Math.Min(one, two); var b = Math.Max(one, two); var current = a * stones; var max = b * stones; var difference = b - a; if(a == b){ Console.WriteLine(current); } else{ var ansString = new StringBuilder(); while(current <= max){ ansString.Append(current.ToString() + " "); current += difference; } Console.WriteLine(ansString); } } } }`

+ 3 comments The instructions for this challenge say that n is the number of "non-zero stones." But based on the sample cases described, n includes the zero stone.

+ 10 comments For anybody stuck on this one, they have some tricky inputs in some of the test cases. Remember that it has to print the list from least to greatest. Think about the problem like this: You know that you have some number of 'a's less than n and some number of 'b's less than n. The minimum number on the last stone would then be (n-1) * a (or b if b is less than a) and the maximum number is (n-1) * b. These can be rewritten as: min = ((n-1)* a) + (0 * b) and vice versa. Now all you have to do is solve like so, next iteration = ((n-1-1)*a) + (1 *b) and so on. Hope this helps.

+ 6 comments Either I am really thick (I hope so, I hope I'm just not getting it), or this problem is just stupid. I don't understand the problem explanation at all, because it doesn't explain anything in particular, it just hints to a pattern and states the answer to a testcase, but not WHY the answer is correct in regard to the dumb story.

I suppose we have to return a set of the largest numbers of all possible variations of the differences? If so, why the superfluous and distracting story? It doesn't offer any analogies relevant to the problem, which actually isn't even a problem at all, but merely a task that doesn't serve any purpose.

That is, if I am not fundamentally misunderstanding everything. In this case I'll gladly admit I'm an idiot, if this means I can solve this challenge.

Please enlighten me, I'd appreciate it.

+ 8 comments Python solution:

`print ' '.join(map(str,sorted({x*a+(n-1-x)*b for x in xrange(n)})))`

Sort 760 Discussions, By:

Please Login in order to post a comment