IBMOA #26
Find Y Value
Estimated EasyJudge-ready
Topics (AI-labelled)Bits & MathGreedy
Given a fixed-length binary string x, construct a binary string y of the same length containing at most maxSet 1s so that the unsigned value of x XOR y is maximized. Output y; leading 0s are allowed.
Input
The first line contains bits maxSet, and the second line contains x. On this site 1≤bits≤100000, 0≤maxSet≤bits.
Output
Output the binary string y of the same length.
Example 1
Input:
4 2
1001
Output:
0110
Example 2
Input:
3 3
111
Output:
000
Example 3
Input:
4 1
0000
Output:
1000
Example notes
The examples give 0110, 000 and 1000 respectively.
Editorial
Loading solution…