INS14C - Digo plays with Numbers
Digo and his friend Sharry have completed their missions and were relaxing. Both of them love mathematics and love to play with numbers. They have a book in which several binary strings are written. Digo comes up with an idea of an interesting game. He asks Sharry to think of a number K, which is less than or equal to the length of the string N. Both players play alternately. In his turn, a person can remove any bit from the binary string. Digo removes such as to maximize the value of the leftover binary string while Sharry plays to minimze the string. This process continues till K binary digits are left. You have to tell those K binary digits left after the game is over.
It is given that Sharry always plays first.
The first line consists of a single integer T, denoting the number of test cases.
2*T lines follow. For every test case, the first line consists of two integers N and K, denoting the initial length of the string and its length at the end of the game. The second line for the test case contains the initial binary string of length N.
For each test case print the final string left after removal of characters.
1 <= T <= 1000
1 <= N <= 1000
1 <= K <= N
dwij28: Just got AC with Python3 at less than half your PyPy time :P. It's exactly this kind of problems where optimizing Python code is fun, because you have to know what you're doing rather than have the compiler figure it out for you.
Python 2.7 gets a TLE, PyPy gets an AC. I am too lazy to optimize or write ad-hoc string problems in C++.
" a person CAN remove any bit", wrongly worded question - that "can" should not be there, it costed me 2 wa.
found it after few WA, missed that K can be Equal to N so the string printed is same as readed.Last edit: 2015-01-22 22:34:58
Getting strange "Internal Error" ...any ideas why ? Thanks
@surya kiran sir : can u plz tell me where i m going wrong http://ideone.com/fork/UhKKd6
@Surya kiran.. pls help..getting wrong answer..( Submission id 12162332 )
My 50th :)
pls help getting wa:( http://ideone.com/0hts07