#C7117. Shortest String Reduction
Shortest String Reduction
Shortest String Reduction
You are given a string s and a non-negative integer k. You must perform an operation exactly k times, where in each operation you remove exactly 2 characters from the string. The task is to determine the length of the remaining string after performing all operations.
Formally, if the initial length of the string is \(n\), then after performing the operation exactly \(k\) times, the length becomes \(n - 2k\). It is guaranteed that \(2k \le n\). Your program should process multiple test cases.
Example:
- For
s = "abccba"
andk = 2
, the remaining length is \(6 - 2*2 = 2\). - For
s = "hellocode"
andk = 1
, the remaining length is \(9 - 2*1 = 7\).
inputFormat
The input is read from standard input (stdin
) and has the following format:
T s1 k1 s2 k2 ... sT kT
Where:
T
is the number of test cases.- Each test case consists of a string
s
and an integerk
separated by a space. The strings
does not contain spaces and \(2k\) is guaranteed not to exceed the length ofs
.
outputFormat
For each test case, output a single integer on a new line representing the length of the string after performing the removal operations, using standard output (stdout
).
3
abccba 2
hellocode 1
abc 1
2
7
1
</p>