Skip to content
neoideasblog

neoideasblog

  • Home
    • Privacy Policy
    • About Us
    • Contact Us
    • Terms
  • Trivia
  • Results
  • Admit Cards
  • Sitemaps
  • Toggle search form

Sum of Substrings solution codeforces

Posted on May 31, 2022May 31, 2022 By Admin No Comments on Sum of Substrings solution codeforces

Sum of Substrings solution codeforces

You are given a binary string ss of length nn. Let’s define didi as the number whose decimal representation is sisi+1sisi+1 (possibly, with a leading zero). We define f(s)f(s) to be the sum of all the valid didi. In other words, f(s)=∑i=1n−1dif(s)=∑i=1n−1di. For example, for the string s=1011s=1011:
  • d1=10d1=10 (ten);
  • d2=01d2=01 (one)
  • d3=11d3=11 (eleven);
  • f(s)=10+01+11=22f(s)=10+01+11=22.
In one operation you can swap any two adjacent elements of the string. Find the minimum value of f(s)f(s) that can be achieved if at most kk operations are allowed.
ALSO READ:-   [Ques] As mentioned in the lyrics of "The Star-Spangled Banner," a rampart is a what?
Input

Sum of Substrings solution codeforces

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1051≤t≤105). Description of the test cases follows. First line of each test case contains two integers nn and kk (2≤n≤1052≤n≤105, ≤k≤1090≤k≤109) — the length of the string and the maximum number of operations allowed. The second line of each test case contains the binary string ss of length nn, consisting of only zeros and ones.
ALSO READ:-   [Ques] Where is the world's largest university by enrollment size?
It is also given that sum of nn over all the test cases doesn’t exceed 105105.
Output
For each test case, print the minimum value of f(s)f(s) you can obtain with at most kk operations.
Example

Sum of Substrings solution codeforces

input
Copy
3
4 0
1010
7 1
0010100
5 2
00110
output
Copy
21
22
12
Note

Sum of Substrings solution codeforces

  • For the first example, you can’t do any operation so the optimal string is ss itself. f(s)=f(1010)=10+01+10=21f(s)=f(1010)=10+01+10=21.
  • For the second example, one of the optimal strings you can obtain is “0011000“. The string has an ff value of 2222.
  • For the third example, one of the optimal strings you can obtain is “00011“. The string has an ff value of 1212.

    SOLUTION

    “Click here“

Admin

I am the Founder and the creator of the blog neoideasblog.com where we share latest trivia questions and answers on a daily basis.

Trivia Tags:Sum of Substrings, Sum of Substrings solution, Sum of Substrings solution codeforces

Post navigation

Previous Post: Shoe Shuffling solution codeforces
Next Post: Max GEQ Sum solution codeforces

Related Posts

[Question] What is the capital of New Zealand? Trivia
Minimum Obstacle Removal to Reach Corner solution leetcode- You are given a 0-indexed 2D integer array grid of size m x n. Each cell has one of two values Trivia
What is the only bird that hibernates ? Trivia
[Question] Abraham Lincoln’s face appears on what piece of U.S. paper currency? Trivia
[Neo] Which U.S. state is home to these giant shuttlecocks? Trivia
[Question] 9. In which play do Brutus and Cassius, amongst others conspire to assassinate a Roman dictator? Trivia

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Archives

  • June 2022
  • May 2022
  • April 2022

Categories

  • Admit Cards
  • Results
  • Trivia

Disclaimer

Disclaimer: Our website name Neoideasblog.com. we are just a news portal that covers various updates and stories.

Copyright © 2022 neoideasblog.

Powered by PressBook Grid Blogs theme