All Tracks Problem

String Maximisation
Tag(s):

Very-Easy

Problem
Editorial
Analytics

Ayush is a very stylish boy, or in in our Jolu lingo, he is quite a “ketabaaj”. And due to this, he is quite well known among everyone. But he has a problem. He always likes to exaggerate things, presenting everything maxed out, i.e. maximum of everything!!!

So one fine day he was playing with a few “binary strings”, consisting of only 0’s and 1’s. So he thought why not “exaggerate” them too. But he got baffled at the problem and has thus approached you to get some help.

You will be given a “binary string” S, and a number K. You have to produce the maximum possible decimal equivalent of the given “binary string” by changing digits at most K times, i.e. changing a ‘0’ to ‘1’ and vice-versa.

INPUT
First line will have a single integer T, denoting number of test cases.
Next T lines of input will consist of two parts separated by a space. First part will be “binary string” S consisting only of 0’s and 1’s. Second part will be a single integer K.

OUTPUT
Output a single integer denoting maximum decimal value per test case. Output for each test case should be in a new line.

CONSTRAINTS

  • 1<=T<=105
  • 1<=len(S)<=50
  • 0<=K<=50

SAMPLE INPUT
1
10010 1
SAMPLE OUTPUT
26
Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

Jalpaiguri Government Engineering College

Challenge Name

Code Chronicles Season 3

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?