Sereja and number game 2

I was not able to solve sereja and number game 2 problem of jan15. Can anyone provide me the editorial or any hint on solving the problem.


Editorial for this problem will be served soon! Till then Read this. It will help you understand what the problem statement says.

Here is a little explaination-

Given a number lets say 123. We have to find the permutations(which can be 213,312, 321,231 or 123 also) of this number which gives minimum mod value with B[i] ( i varies from 1 to n ). The given test case illustrates only one possible permutation.

For test case 1 i.e. 123

here b[] = {2,3}

    Permutation    mod value summation
        123              1+0
        132              0+0
        231              1+0
        213              1+0
        321              1+0
        312              0+0

so permuations with minimum mod value are 132 and 312 but the optimal solution is 312.
In second case i.e. 123457, 754312(output) will fetch you some marks but maximum marks will be fetched by 754321(you can check why).

Hope this helps. :slight_smile:

1 Like

where is the editorial!?

Thanks you :smiley:

you are welcome :slight_smile: