Educational Codeforces Round 161 (Rated for Div. 2) D. Berserk Monsters
3261. Count Substrings That Satisfy K-Constraint II
You are given a binary string
sand an integerk.You are also given a 2D integer array
queries, wherequeries[i] = [li, ri].A binary string satisfies the k-constraint if either of the following conditions holds:
- The number of
0‘s in the string is at mostk.- The number of
1‘s in the string is at mostk.Return an integer array
answer, whereanswer[i]is the number of substrings ofs[li..ri]that satisfy the k-constraint.
3260. Find the Largest Palindrome Divisible by K
You are given two positive integers
nandk.An integer
xis called k-palindromic if:
xis a palindrome.
xis divisible byk.Return the largest integer having
ndigits (as a string) that is k-palindromic.Note that the integer must not have leading zeros.
3259. Maximum Energy Boost From Two Drinks
You are given two integer arrays
energyDrinkAandenergyDrinkBof the same lengthnby a futuristic sports scientist. These arrays represent the energy boosts per hour provided by two different energy drinks, A and B, respectively.You want to maximize your total energy boost by drinking one energy drink per hour. However, if you want to switch from consuming one energy drink to the other, you need to wait for one hour to cleanse your system (meaning you won’t get any energy boost in that hour).
Return the maximum total energy boost you can gain in the next
nhours.Note that you can start consuming either of the two energy drinks.
3258. Count Substrings That Satisfy K-Constraint I
You are given a binary string
sand an integerk.A binary string satisfies the k-constraint if either of the following conditions holds:
- The number of
0‘s in the string is at mostk.- The number of
1‘s in the string is at mostk.Return an integer denoting the number of substrings of
sthat satisfy the k-constraint.
3257. Maximum Value Sum by Placing Three Rooks II
You are given a
m x n2D arrayboardrepresenting a chessboard, whereboard[i][j]represents the value of the cell(i, j).Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other.
Return the maximum sum of the cell values on which the rooks are placed.
3256. Maximum Value Sum by Placing Three Rooks I
You are given a
m x n2D arrayboardrepresenting a chessboard, whereboard[i][j]represents the value of the cell(i, j).Rooks in the same row or column attack each other. You need to place three rooks on the chessboard such that the rooks do not attack each other.
Return the maximum sum of the cell values on which the rooks are placed.
3255. Find the Power of K-Size Subarrays II
You are given an array of integers
numsof lengthnand a positive integerk.The power of an array is defined as:
- Its maximum element if all of its elements are consecutive and sorted in ascending order.
- -1 otherwise.
You need to find the power of all subarrays of
numsof sizek.Return an integer array
resultsof sizen - k + 1, whereresults[i]is the power ofnums[i..(i + k - 1)].