brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1955C - Inhabitant of the Deep Sea

We are given a line of ships, each with some durability, and a fixed attack pattern that always targets the current leftmost surviving ship, then the current rightmost surviving ship, and repeats this alternation until a total of $k$ attacks have been made or all ships sink.

codeforcescompetitive-programminggreedyimplementationmath
CF 483B - Friends and Presents

Codeforces 483B: Friends and Presents

codeforcescompetitive-programmingbinary-searchmath
CF 1975B - 378QAQ and Mocha's Array

Codeforces 1975B: 378QAQ and Mocha's Array

codeforcescompetitive-programmingbrute-forcegreedymathsortings
CF 1975E - Chain Queries

Codeforces 1975E: Chain Queries

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similarimplementationtrees
CF 485A - Factory

Codeforces 485A: Factory

codeforcescompetitive-programmingimplementationmathmatrices
CF 1958C - Firewood

Monocarp has a single log of wood that weighs exactly $2^n$ grams. He needs to split this log into pieces such that he can assemble exactly $k$ grams of wood for today's fireplace, leaving the remaining $2^n-k$ grams for tomorrow.

codeforcescompetitive-programming*special
CF 1942F - Farmer John's Favorite Function

We have an array $a$, and a recursively defined value: $$f(1)=sqrt{a1}, qquad f(i)=sqrt{f(i-1)+ai}.$$ After every point update $ak leftarrow x$, we need the integer part of $f(n)$. The first obstacle is that the recurrence uses real numbers.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementationmath
CF 1976E - Splittable Permutations

Codeforces 1976E: Splittable Permutations

codeforcescompetitive-programmingcombinatoricsdata-structuresdfs-and-similargreedymathtrees
CF 1967E1 - Again Counting Arrays (Easy Version)

We are given a fixed starting height $b0$ and we imagine building an integer path $b0, b1, ldots, bn$ where each step moves by exactly $+1$ or $-1$, but the path is never allowed to go below zero. This is a standard “walk on the non-negative integers” with unit steps.

codeforcescompetitive-programmingcombinatoricsdpfftmath
CF 1965A - Everything Nim

We are given several independent games, each defined by a list of piles containing stones. Two players alternate turns.

codeforcescompetitive-programminggamesgreedymathsortings
CF 1958A - 1-3-5

We are asked to construct an exact sum using coins of values 1, 3, and 5. For each target amount n, we want to pay exactly n using any number of 3 and 5 coins, and we are only forced to use 1-coins when it becomes unavoidable.

codeforcescompetitive-programming*specialdp
CF 1965E - Connected Cubes

We are given an $n times m$ grid sitting at height $z=1$, where each cell already contains a unit cube with a color.

codeforcescompetitive-programmingconstructive-algorithmsgames
CF 1951G - Clacking Balls

We are given a circle of baskets numbered from 1 to $m$, and $n$ balls initially placed in distinct baskets. Alice repeatedly chooses one of the balls uniformly at random and moves it clockwise to the next basket.

codeforcescompetitive-programmingcombinatoricsmathprobabilities
CF 1954A - Painting the Ribbon

We are asked to decide whether Alice can paint a ribbon of n parts using m colors such that Bob, who can repaint at most k parts into the same color, cannot make the entire ribbon monochromatic.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1955D - Inaccurate Subsequence Search

We are asked to count subsegments of length m in an array a that are “good” relative to another array b of length m. A subsegment is considered good if, after rearranging its elements, at least k of them match elements from b.

codeforcescompetitive-programmingdata-structurestwo-pointers
CF 1976C - Job Interview

Codeforces 1976C: Job Interview

codeforcescompetitive-programmingbinary-searchdpgreedyimplementationtwo-pointers
CF 1956E1 - Nene vs. Monsters (Easy Version)

We are given a circle of n monsters, each with an initial energy level ai. They are numbered from 1 to n, and each monster attacks its clockwise neighbor simultaneously in a single round.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 1950D - Product of Binary Decimals

We are given up to 50,000 independent queries. For each query, a number n is provided, where 1 ≤ n ≤ 100000. A number is called a binary decimal if every digit in its usual decimal representation is either 0 or 1. Examples include 1, 10, 11, 101, and 1001.

codeforcescompetitive-programmingbrute-forcedpimplementationnumber-theory
CF 493A - Vasya and Football

We are given the names of the home and away teams, followed by a chronological list of card events during a football match. Each event specifies the minute, which team the player belongs to, the player's jersey number, and whether the referee gives a yellow card or a red card.

codeforcescompetitive-programmingimplementation
CF 1951I - Growing Trees

We are given a connected simple undirected graph with up to 50 vertices and at most 50 edges. Each edge can be used multiple times in a constructed multigraph, and we control how many copies of each edge we create through a non-negative integer array $x$.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsflowsgraphsgreedy
CF 1956F - Nene and the Passing Game

We are given a sequence of basketball players, each with a passing range expressed as an interval $[li, ri]$. The players are numbered from 1 to $n$.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdsugraphssortings
CF 1973B - Cat, Fox and the Lonely Array

Codeforces 1973B: Cat, Fox and the Lonely Array

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresgreedymathtwo-pointers
CF 1976B - Increase/Decrease/Copy

Codeforces 1976B: Increase/Decrease/Copy

codeforcescompetitive-programminggreedyimplementation
CF 1945C - Left and Right Houses

We are given a village with n houses aligned in a row. Each resident has a preference for which side of a street they want to live on: left (0) or right (1).

codeforcescompetitive-programmingbrute-force
CF 1942A - Farmer John's Challenge

We need to construct an array of length n such that exactly k of its cyclic shifts are sorted in nondecreasing order. A cyclic shift chooses some position as the new beginning of the array and wraps the remaining elements around.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1943C - Tree Compass

We are given a tree and an operation that does not act on a single node, but on a layer of nodes: if we pick a center vertex $v$ and a distance $d$, we recolor every vertex whose shortest-path distance from $v$ is exactly $d$.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargreedytrees
CF 1950E - Nearly Shortest Repeating Substring

We are given a string s of length n. We want to find the smallest possible length L such that there exists a pattern string k of length L, repeated exactly n / L times, producing a string c of length n, and c differs from s in at most one position.

codeforcescompetitive-programmingbrute-forceimplementationnumber-theorystrings
CF 1945D - Seraphim the Owl

We are given a queue of n people waiting to ask Seraphim the Owl a question. Kirill arrives at the end of the line and wants to move forward so that he is among the first m people.

codeforcescompetitive-programmingdpgreedy
Sindarin Vocabulary: Numbers

Complete Sindarin number system: cardinals 1–1000, ordinals 1st–10th, number compounds, duodecimal counting, and number words in place names.

sindarinvocabularynumberstolkien
CF 485B - Valuable Resources

We are asked to build a square city on a 2D Cartesian map such that it encloses all given mines, represented as points with integer coordinates. The sides of the square must remain parallel to the axes, and our goal is to minimize the area of the square.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1967A - Permutation Counting

We are given a set of cards, each labeled with a number from 1 to n. For each number i, we have ai cards of that type.

codeforcescompetitive-programmingbinary-searchgreedyimplementationmathsortings
CF 1976F - Remove Bridges

Codeforces 1976F: Remove Bridges

codeforcescompetitive-programmingdata-structuresdfs-and-similardpgreedysortingstrees
CF 1958G - Observation Towers

Each observation tower sits at a fixed position on a number line from 1 to n and has a current viewing radius given by its height. A tower can “see” every integer point whose distance from its position does not exceed its height.

codeforcescompetitive-programming*special
HSK 3 Grammar Points

Comprehensive guide to HSK 3 grammar: 把 construction, 被 passive, complements, conditionals, and intermediate patterns — with tables and examples.

chinesehsk3grammarintermediatehskb1
CF 1955G - GCD on a grid

We are given a rectangular grid of integers. A move starts at the top-left cell and ends at the bottom-right cell, and at each step we can only go either one cell down or one cell right. Every such move sequence forms a monotone path.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpimplementationmathnumber-theory
CF 1944A - Destroying Bridges

We are asked to consider a network of islands where initially every pair of islands is connected by a bridge. There are n islands, numbered from 1 to n, and Everule lives on island 1. Dominater can destroy up to k bridges to reduce the number of islands that Everule can reach.

codeforcescompetitive-programminggraphsgreedymath
CF 491B - New York Hotel

The city is a rectangular grid. Every hotel and every restaurant is located at an intersection with coordinates $(x,y)$.

codeforcescompetitive-programminggreedymath
CF 491C - Deciphering

We are asked to decipher a message that has been encoded by a simple substitution cipher. Each letter in the original message is replaced with a fixed letter, so the mapping is one-to-one: different letters map to different letters, and the same letter always maps to the same…

codeforcescompetitive-programmingflowsgraph-matchings
CF 1949C - Annual Ants' Gathering

Each vertex of the tree initially contains exactly one ant. A move chooses an edge $(u,v)$ and orders all ants currently gathered at $u$ to move to $v$. The ants obey only when the destination already contains at least as many ants as the source.

codeforcescompetitive-programmingdfs-and-similardpgreedytrees
HSK 9 Grammar Points

Comprehensive guide to HSK 9 grammar: native-level classical Chinese, literary production, oral defense mastery, and full C2+ control of written and spoken registers.

chinesehsk9grammarnativehskc2
CF 1950F - 0, 1, 2, Tree!

We are asked to construct a rooted tree with a specific number of vertices having 0, 1, or 2 children. The input gives three numbers: a vertices with 2 children, b vertices with 1 child, and c vertices that are leaves.

codeforcescompetitive-programmingbitmasksbrute-forcegreedyimplementationtrees
CF 1975I - Mind Bloom

Codeforces 1975I: Mind Bloom

codeforcescompetitive-programmingdp
CF 1949E - Damage per Second

We are asked to distribute a fixed number of skill points between two attributes: damage per hit and hits per second, in order to minimize the total time to kill a sequence of monsters.

codeforcescompetitive-programmingbrute-forcemath
CF 1973E - Cat, Fox and Swaps

Codeforces 1973E: Cat, Fox and Swaps

codeforcescompetitive-programminggraphsmathsortings
CF 1974B - Symmetric Encoding

Codeforces 1974B: Symmetric Encoding

codeforcescompetitive-programmingimplementationsortingsstrings
CF 1945H - GCD is Greater

We are given an array of integers, and two players split the array into two groups. Kirill is allowed to choose a subset that is neither too small nor too large, specifically at least two elements and at most $n-2$ elements. Those chosen elements form the red group.

codeforcescompetitive-programmingbrute-forcedata-structuresmathnumber-theory
CF 1945G - Cook and Porridge

We are simulating a queue of students where the front of the queue is repeatedly served for a limited number of minutes. Each student, once served, leaves to “process” their porridge for a fixed number of minutes, and then returns to the queue.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresimplementation
CF 1975D - Paint the Tree

Codeforces 1975D: Paint the Tree

codeforcescompetitive-programmingbrute-forcedfs-and-similardpgreedyshortest-pathstrees
CF 1975F - Set

Codeforces 1975F: Set

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdfs-and-similardivide-and-conquerdpmath
CF 1954E - Chain Reaction

We are given a line of monsters, each with some initial health. One operation consists of choosing a single monster as the starting point of a “chain lightning”.

codeforcescompetitive-programmingbinary-searchdata-structuresdsugreedyimplementationmathnumber-theory
CF 1950C - Clock Conversion

We are given times expressed in the 24-hour clock format, for example 00:00 for midnight, 13:45 for one forty-five in the afternoon, or 23:59 for one minute before midnight. Our task is to convert each time into the 12-hour clock format, which uses the familiar AM and PM labels.

codeforcescompetitive-programmingimplementationmath
CF 1949G - Scooter

Each building has two independent pieces of information. The first string describes what class is held there. A building may need a mathematics professor, a computer science professor, or no professor at all. The second string describes which professor is initially located there.

codeforcescompetitive-programminggraphsgreedy
CF 1942D - Learning to Paint

We are asked to help Elsie evaluate her paintings on a 1D canvas of n cells. Each cell can be painted or left empty, and the painting's beauty is determined by a 2D array a.

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similardpgreedyimplementationsortings
CF 1955B - Progressive Square

We are given an $n times n$ grid that is fully determined by three values: the top-left cell, and two fixed increments that govern movement downwards and rightwards. Moving one step down always adds $c$, and moving one step right always adds $d$.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresimplementationsortings
CF 1958B - Clock in the Pool

The clock is not a normal continuous display, it behaves like a repeating cycle of three states. Every cycle has length $3k$ seconds.

codeforcescompetitive-programming*specialmath
CF 1942H - Farmer John's Favorite Intern

We are asked to maintain a rooted tree where each node starts with zero peaches. Two kinds of operations can happen. In a growth operation at node $x$, we can increase the number of peaches on the parent of $x$ or any node in the subtree of $x$.

codeforcescompetitive-programmingdata-structuresdpflowstrees
CF 1943E1 - MEX Game 2 (Easy Version)

We are asked to simulate a two-player game on an array of integers, but with a compressed representation where we only know the frequencies of each integer.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedy
CF 1967D - Long Way to be Non-decreasing

We are given an array where each position contains a value in the range $1$ to $m$, and a second array that defines a deterministic transformation on values: every value $x$ has a fixed replacement $bx$.

codeforcescompetitive-programmingbinary-searchdfs-and-similargraphsimplementationshortest-pathstwo-pointers
CF 1958D - Staircase

We are given a line of staircase steps, each step either needing repair or already fine. If a step is fine, it behaves like a zero in the input. If it is broken, it carries a positive cost value that represents its repair difficulty. The repair process is constrained by days.

codeforcescompetitive-programming*special
CF 1953A - Accuracy-Preserving Summation Algorithm

We are given a long sequence of floating-point numbers, and we are asked to output a description of how to compute their total sum.

codeforcescompetitive-programming*special
CF 1956A - Nene's Game

We are given an increasing list of positions, and a process that repeatedly deletes players from a line. In each round, we look at the current lineup and try to remove the players standing at positions $a1, a2, ldots, ak$.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgamesgreedy
CF 1952A - Are You a Robot, Again?

In this problem, we are given a string of digits that a robot has produced. The robot operates under a simple but peculiar rule: for each digit in the string, if the digit is even, it will remain in the output string as-is.

codeforcescompetitive-programming*specialstrings
CF 1956E2 - Nene vs. Monsters (Hard Version)

We are given a circle of monsters, each with an energy level. The monsters attack their neighbor in a fixed clockwise order: monster 1 attacks monster 2, monster 2 attacks monster 3, and so on, with the last monster attacking the first.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmath
CF 1942G - Bessie and Cards

The deck contains four kinds of cards. A draw-0 card consumes one playable card from your hand and gives nothing back. A draw-1 card replaces itself. A draw-2 card consumes one card and gives two new cards, so it increases your future drawing power by one.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1954D - Colored Balls

We are given a collection of balls, each assigned one of n distinct colors, where color i has ai balls. We are allowed to group these balls, but each group can have at most two balls, and no two balls in the same group can have the same color.

codeforcescompetitive-programmingcombinatoricsdpmathsortings
CF 491A - Up the hill

Codeforces 491A: Up the hill

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1967B2 - Reverse Card (Hard Version)

We are asked to count ordered pairs of integers $(a, b)$ with $1 le a le n$ and $1 le b le m$ such that $b cdot gcd(a, b)$ is divisible by $a+b$. The inputs are multiple test cases, each specifying a pair of limits $n$ and $m$.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1951E - No Palindromes

We are given a string and we are allowed to cut it into contiguous pieces. The goal is to decide whether we can cut it so that every resulting piece is not a palindrome. If it is possible, we must also construct one such cut.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdivide-and-conquergreedyhashingimplementationmathstrings
CF 1974D - Ingenuity-2

Codeforces 1974D: Ingenuity-2

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1967C - Fenwick Tree

We are asked to reverse a Fenwick Tree construction. A Fenwick Tree is normally defined for an array a of length n such that each element sk stores the sum of a contiguous subarray of a whose length is the lowest set bit of k.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdata-structuresdpmathtrees
CF 1956C - Nene's Magical Matrix

We are given a square matrix of size $n times n$ initially filled with zeroes. Nene can perform two types of operations: either set an entire row to a permutation of $1$ through $n$ or set an entire column to such a permutation.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1958E - Yet Another Permutation Constructive

We are given a permutation, which is just an ordering of the numbers from 1 to n. We repeatedly apply a transformation that removes elements which are strictly smaller than at least one of their immediate neighbors.

codeforcescompetitive-programming*specialconstructive-algorithms
CF 1943F - Minimum Hamming Distance

We are given two binary strings of equal length. The first string, call it the reference string, defines a constraint on how a valid target string must behave. The second string is the one we want to stay as close as possible to after we adjust it into a valid configuration.

codeforcescompetitive-programmingdp
CF 1942B - Bessie and MEX

We are given an array a of length n, constructed from some unknown permutation p of the integers 0 through n-1. Each element of a satisfies the relation a[i] = MEX(p[1..i]) - p[i]. The task is to reconstruct any valid permutation p that produces this a.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1974E - Money Buys Happiness

Codeforces 1974E: Money Buys Happiness

codeforcescompetitive-programmingdp
CF 1957A - Stickogon

We are given a collection of sticks, each with an integer length. The goal is to build as many regular polygons as possible using these sticks, with the restriction that each side of a polygon must be exactly one stick, and no stick can be reused.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 488B - Candy Boxes

The task is to reconstruct a set of four integers representing candy counts in boxes such that three properties are equal: the arithmetic mean, the median, and the range. We are given some subset of these four numbers (0 to 4) in arbitrary order.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmath
CF 1945F - Kirill and Mushrooms

Kirill wants to gather mushrooms under a Wise Oak to brew an elixir. Each mushroom has a magic power, and the strength of an elixir made from a group of mushrooms is the product of the count of mushrooms and the minimum magic power among them.

codeforcescompetitive-programmingdata-structuressortings
CF 495B - Modular Equations

Codeforces 495B: Modular Equations

codeforcescompetitive-programmingmathnumber-theory
CF 1955A - Yogurt Sale

Maxim wants to buy exactly n yogurts from a store where a single yogurt costs a burles, but there is a promotion offering two yogurts for b burles. For each test case, we must calculate the minimum amount he can spend to buy exactly n yogurts.

codeforcescompetitive-programmingmath
CF 1958I - Equal Trees

We are given two rooted trees on the same labeled vertex set from 1 to n, both rooted at 1. Each tree is described by its parent array, so every node knows its immediate parent except the root.

codeforcescompetitive-programming*specialgraphsmeet-in-the-middle
CF 493D - Vasya and Chess

We have an $n times n$ board. The white queen starts at the top-left corner $(1,1)$, and the black queen starts at the top-right corner $(1,n)$. Every other square contains a green pawn. A move is mandatory. On each turn, a player must capture some piece with their queen.

codeforcescompetitive-programmingconstructive-algorithmsgamesmath
CF 1951C - Ticket Hoarding

The task is to buy exactly k concert tickets over n days, with each day offering a ticket price ai. You are limited to buying at most m tickets per day. Additionally, every ticket you buy increases the price of all future tickets by the number of tickets bought on that day.

codeforcescompetitive-programminggreedymathsortings
CF 1975H - 378QAQ and Core

Codeforces 1975H: 378QAQ and Core

codeforcescompetitive-programminggreedystrings
CF 1950A - Stair, Peak, or Neither?

We are given three digits, a, b, and c, and must classify their relationship. A sequence is called a stair when the values strictly increase from left to right, meaning a < b < c.

codeforcescompetitive-programmingimplementation
CF 1973A - Chess For Three

Codeforces 1973A: Chess For Three

codeforcescompetitive-programmingbrute-forcedpimplementationmath
LeetCode 3890 - Integers With Multiple Sum of Two Cubes

The problem asks us to find all integers x less than or equal to a given integer n such that x can be expressed as the sum of cubes of two positive integers in at least two distinct ways.

leetcodemediumhash-tablesortingcountingenumeration
LeetCode 3792 - Sum of Increasing Product Blocks

The problem defines a sequence of blocks, where each block contains the product of a consecutive range of integers.

leetcodemediummathsimulation
LeetCode 3889 - Mirror Frequency Distance

We are given a string s containing only lowercase English letters (a-z) and digits (0-9). Each character has a corresponding mirror character: - Letters are mirrored across the alphabet. - a ↔ z - b ↔ y - c ↔ x - and so on. - Digits are mirrored across the digit range.

leetcodemediumhash-tablestringcounting
LeetCode 3875 - Construct Uniform Parity Array I

The problem asks us to determine if it is possible to construct a new array nums2 of the same length as nums1 where all elements are either all odd or all even.

leetcodeeasyarraymath
LeetCode 3791 - Number of Balanced Integers in a Range

Here is the full, detailed technical solution guide for LeetCode 3791 - Number of Balanced Integers in a Range, following your requested structure. The problem asks us to count all integers between low and high inclusive that are balanced.

leetcodeharddynamic-programming
LeetCode 3885 - Design Event Manager

The problem asks us to design an EventManager class that manages a set of events, each identified by a unique eventId and associated with a priority.

leetcodemediumarrayhash-tabledesignheap-(priority-queue)ordered-set
LeetCode 3790 - Smallest All-Ones Multiple

This problem asks us to find the smallest positive integer composed entirely of the digit 1 that is divisible by a given integer k. The input k is guaranteed to be between 2 and 100,000.

leetcodemediumhash-tablemath
LeetCode 3884 - First Matching Character From Both Ends

This problem gives us a string s of length n consisting of lowercase English letters. For every index i, we compare two characters: - The character at position i, which is s[i] - The character at the mirrored position from the other end, which is s[n - i - 1] We must find the…

leetcodeeasytwo-pointersstring
LeetCode 3882 - Minimum XOR Path in a Grid

We are given an m × n grid of integers. Starting from the top-left cell (0, 0), we must reach the bottom-right cell (m - 1, n - 1) by moving only right or down.

leetcodemediumarraydynamic-programmingbit-manipulationmatrix
LeetCode 3789 - Minimum Cost to Acquire Required Items

This problem asks us to determine the minimum cost required to acquire a set of items that satisfy two separate type requirements. We have three types of items: type 1, type 2, and type 3.

leetcodemediummathgreedy
LeetCode 3883 - Count Non Decreasing Arrays With Given Digit Sums

The problem asks us to compute the number of non-decreasing arrays of integers where each integer satisfies a specific digit sum constraint.

leetcodehardarraydynamic-programmingprefix-sum
LeetCode 3880 - Minimum Absolute Difference Between Two Values

The problem gives us an integer array nums where every element is guaranteed to be one of three values: 0, 1, or 2.

leetcodeeasyarrayenumeration
LeetCode 3788 - Maximum Score of a Split

The problem asks us to maximize a "score" obtained by splitting an integer array nums at a valid index i. For each split index i, the score is calculated as the sum of all elements from the beginning of the array up to i (prefixSum) minus the minimum value in the remaining…

leetcodemediumarrayprefix-sum
LeetCode 3881 - Direction Assignments with Exactly K Visible People

We are given n people standing in a line, indexed from 0 to n - 1. Each person independently chooses one of two directions: - 'L' means the person is visible only to people on their right. - 'R' means the person is visible only to people on their left.

leetcodemediummathcombinatorics