brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1039D - You Are Given a Tree

We are working with a tree where we want to select several simple paths, with a strict rule that no vertex can belong to more than one selected path.

codeforcescompetitive-programmingdata-structuresdptrees
CF 1039C - Network Safety

We are given a network of servers where each server has an integer label (an encryption key) in a fixed bit range. Some pairs of servers are connected, and a connection is considered safe only if the two endpoints currently hold different values.

codeforcescompetitive-programmingdfs-and-similardsugraphsmathsortings
CF 1039A - Timetable

We are given a fixed sequence of departure times from station A, strictly increasing, and for each bus we also know a constraint on how “late” it can possibly appear in the arrival order at station B.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedymath
CF 1040A - Palindrome Dance

We are given a line of dancers, each occupying a fixed position. Every dancer must end up wearing either a white suit or a black suit, and some of these suits are already fixed while others are undecided.

codeforcescompetitive-programminggreedy
CF 1041E - Tree Reconstruction

We are given a multiset of information that originally came from a rooted structure, but the structure itself is hidden. There exists a tree on vertices numbered from 1 to n, and each vertex has a unique label equal to its number.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgraphsgreedy
CF 1041C - Coffee Break

We are given a set of moments inside a working day when Monocarp is willing to drink coffee. Each moment is a specific minute inside a day that lasts from minute 1 to minute m.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedytwo-pointers
CF 1041A - Heist

We are given a set of keyboard indices that survived a burglary. The key hidden structure is that before the theft, all keyboards formed one continuous block of integers, something like x, x+1, x+2, and so on up to some unknown length.

codeforcescompetitive-programminggreedyimplementationsortings
CF 1042E - Vasya and Magic Matrix

We are given a grid where every cell has a numeric value, and a chip starts at a specific cell. From its current position, the chip can only move to cells that have strictly smaller values than the current one.

codeforcescompetitive-programmingdpmathprobabilities
CF 1042C - Array Product

We are given an array of integers, and we repeatedly reduce it until only one value remains. Each reduction step either merges two positions by multiplying their values and storing the result into one of the positions, or removes a single element entirely, but that removal…

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1042A - Benches

We are given several benches, each already occupied by some number of people. Then a group of new people arrives, and each of them must choose a bench and sit there.

codeforcescompetitive-programmingbinary-searchimplementation
CF 1043G - Speckled Band

We are given a long string and many queries, each asking about a substring. For each substring, we imagine splitting it into several consecutive pieces. Among those pieces, identical pieces are considered the same “band”.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerhashingstring-suffix-structuresstrings
CF 1043D - Mysterious Crime

We are given several different observations of the same set of people, each observation being a full ordering of the same $n$ elements.

codeforcescompetitive-programmingbrute-forcecombinatoricsmathmeet-in-the-middletwo-pointers
CF 1043E - Train Hard, Win Easy

We are given a set of participants, each described by two numbers. These two numbers represent how much penalty a participant contributes depending on whether they solve the first task or the second task in a two-person training contest.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortings
CF 1043F - Make It One

We are given a multiset of positive integers, and we are allowed to choose any subset of these numbers. For a chosen subset, we compute the greatest common divisor of all selected elements.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmathnumber-theoryshortest-paths
CF 1043C - Smallest Word

We are given a binary string consisting only of characters a and b. We process its prefixes from left to right in a fixed order, meaning we first decide what to do with the prefix of length 1, then length 2, and so on until the full string.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1043B - Lost Array

We are given a sequence of prefix values a[0], a[1], ..., a[n] where a[0] = 0. The sequence was originally generated from a hidden array x of length k, but that array is no longer available.

codeforcescompetitive-programmingimplementation
CF 1043A - Elections

Each student in the school is forced to distribute a fixed number of votes, denoted by $k$, between two candidates. For every student, we are given how many votes they intend to give to Elodreip.

codeforcescompetitive-programmingimplementationmath
CF 1044D - Deduction Queries

We are dealing with an extremely large conceptual array indexed from 0 up to $2^{30}-1$, but we never actually store its values.

codeforcescompetitive-programmingdata-structuresdsu
CF 1044F - DFS

We are working with a fixed tree on $n$ vertices.

codeforcescompetitive-programmingdata-structures
CF 1044A - The Tower is Going Home

We are given a huge grid, but movement is not about stepping cell by cell. Instead, a rook starts at the bottom-left corner and can teleport along an entire row or column, as long as nothing blocks its straight-line path. There are two kinds of obstacles.

codeforcescompetitive-programmingbinary-searchtwo-pointers
CF 1044E - Grid Sort

We are given a small grid, at most 20 by 20, containing a permutation of the numbers from 1 to nm. The goal is to transform this grid into sorted order when read row by row.

codeforcescompetitive-programmingimplementation
CF 1044B - Intersecting Subtrees

We are given a tree with n vertices, but there is a twist: there are two different labelings of the same underlying tree. In your view, the vertices are numbered from 1 to n and the edges are given in this numbering.

codeforcescompetitive-programmingdfs-and-similarinteractivetrees
CF 1044C - Optimal Polygon Perimeter

We are given a convex polygon with its vertices already listed in clockwise order. The geometry is fixed: we cannot move points, only choose subsets of vertices.

codeforcescompetitive-programmingdpgeometry
CF 1045J - Moonwalk challenge

The input describes a tree where each edge connects two craters and carries a single lowercase letter. If you walk between any two craters, there is exactly one simple path, and that path naturally produces a string formed by concatenating the edge labels along the way.

codeforcescompetitive-programmingdata-structuresstringstrees
CF 1045F - Shady Lady

We are given a fixed set of monomials in two variables, each monomial having the form $x^{ak}y^{bk}$, but with an unknown positive integer coefficient. Before the coefficients are chosen, Ani is allowed to remove at most one monomial.

codeforcescompetitive-programminggeometrymath
CF 1045G - AI robots

We are given a set of robots placed on a number line. Each robot sits at a coordinate and has a fixed symmetric visibility range around its position. Inside that range, it can potentially “see” other robots. However, visibility alone is not enough for interaction.

codeforcescompetitive-programmingdata-structures
CF 1045A - Last chance

We are given a collection of weapons and a line of ships, and we want to assign each destroyed ship to exactly one weapon. Each weapon has a limited way of interacting with ships, and the goal is to maximize how many ships get assigned and destroyed under those constraints.

codeforcescompetitive-programmingdata-structuresflowsgraph-matchingsgraphstrees
CF 1045C - Hyperspace Highways

We are given a connected undirected graph with up to one hundred thousand vertices and up to half a million edges. Each query asks for the shortest path length between two given vertices, measured in number of edges. A crucial extra constraint changes the structure of the graph.

codeforcescompetitive-programmingdfs-and-similargraphstrees
CF 2013B - Battle for Survive

We are given a group of fighters, each starting with a positive strength value. We repeatedly pick two still-alive fighters, and the one with the smaller index is always removed. The survivor’s strength is updated by subtracting the removed fighter’s strength from theirs.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2013C - Password Cracking

Codeforces 2013C: Password Cracking

codeforcescompetitive-programmingconstructive-algorithmsinteractivestrings
CF 1725J - Journey

We are given a weighted tree where each node represents a city and each edge represents a bidirectional road with a travel time. The traveler must design a walk that eventually visits every city at least once.

codeforcescompetitive-programmingdptrees
CF 1725I - Imitating the Key Tree

Working

codeforcescompetitive-programmingcombinatoricsdsutrees
CF 1725C - Circular Mirror

We are given a circle with lamps placed on its boundary in a fixed clockwise order. Between consecutive lamps we know the arc lengths, so the geometry of the circle is fully determined up to rotation.

codeforcescompetitive-programmingbinary-searchcombinatoricsgeometrymathtwo-pointers
CF 1725F - Field Photography

Each row initially contains a contiguous block of contestants placed on an extremely large integer line of columns. Row $i$ occupies every position from $Li$ to $Ri$, so geometrically each row is just a closed interval.

codeforcescompetitive-programmingbitmasksdata-structuressortings
CF 1561D1 - Up the Strip (simplified version)

We are standing on a vertical strip of numbered cells from 1 at the top down to n at the bottom. A token starts at cell n, and we repeatedly move it upward until it reaches cell 1.

codeforcescompetitive-programmingbrute-forcedata-structuresdpmathnumber-theory
CF 1560C - Infinity Table

We are given a rule that fills an infinite grid with positive integers starting from 1. The placement does not proceed row by row or column by column in a simple linear fashion.

codeforcescompetitive-programmingimplementationmath
CF 1560F2 - Nearest Beautiful Number (hard version)

We are asked to construct, for each query, the smallest integer that is at least a given number n, under a digit-restriction constraint. The constraint is that the resulting number may use at most k distinct decimal digits in its representation, with no leading zeros allowed.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdfs-and-similardpgreedy
CF 1560B - Who's Opposite?

We are given three distinct labels that refer to people placed on a perfectly even circle. The circle size is even, but unknown, and the labels are not guaranteed to be consecutive or small.

codeforcescompetitive-programmingmath
CF 1559B - Mocha and Red and Blue

We are given a line of positions, each position holding a tile that must end up colored either red or blue. Some tiles are already fixed, while others are blank and can be assigned either color.

codeforcescompetitive-programmingdpgreedy
CF 1559C - Mocha and Hiking

Codeforces 1559C: Mocha and Hiking

codeforcescompetitive-programmingconstructive-algorithmsgraphs
CF 1559D2 - Mocha and Diana (Hard Version)

We are given two different forests built on the same set of vertices from 1 to n. Each forest is already acyclic, but they may have multiple connected components.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similardsugraphsgreedytreestwo-pointers
CF 1558F - Strange Sort

We are given a permutation that is repeatedly processed by a very specific “two-phase bubble-like” routine. In each iteration, we do not scan all adjacent pairs; instead we alternate between touching only odd edges and only even edges.

codeforcescompetitive-programmingdata-structuressortings
CF 1558A - Charmed by the Game

We are given only the final match statistics of a tennis game: Alice has won a individual games and Borys has won b individual games. We do not know the order of these games, and we also do not know who served first. What we do know is that service alternates strictly every game.

codeforcescompetitive-programmingbrute-forcemath
CF 1558C - Bottom-Tier Reversals

We are given a permutation of length $n$, where $n$ is always odd. The only operation allowed is to take a prefix of odd length and reverse it. Each operation affects only the first $p$ elements, flipping their order, while the rest of the array remains untouched.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1557B - Moamen and k-subarrays

We are given an array of distinct integers and allowed to perform a very specific transformation exactly once. First, we cut the array into exactly k contiguous pieces, each piece non-empty.

codeforcescompetitive-programminggreedysortings
CF 1557A - Ezzat and Two Subsequences

We are given an array of integers, and we must split it into two non-empty groups while preserving every element exactly once. Each group has a score equal to its arithmetic mean, and the goal is to maximize the sum of these two means.

codeforcescompetitive-programmingbrute-forcemathsortings
CF 1554C - Mikasa

We are given a fixed integer n and a range of integers 0, 1, 2, ..., m. Each number in this range is XORed with n, producing a set of values. From this resulting set, we want the smallest non-negative integer that does not appear.

codeforcescompetitive-programmingbinary-searchbitmasksgreedyimplementation
CF 1554D - Diane

We are asked to construct a string of length n using lowercase English letters such that a very strong parity condition holds: every non-empty substring must appear inside the string an odd number of times when we count all occurrences.

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 1553G - Common Divisor Graph

We are given a fixed set of nodes, each labeled by a distinct integer. Two nodes are connected if their labels share any prime factor. This means the graph is determined entirely by the prime factorizations of the given numbers. For each query, we are given two starting nodes.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdsugraphshashingmathnumber-theory
CF 1553F - Pairwise Modulo

We are given a sequence of distinct positive integers. After reading the first k elements, we define a score pk that aggregates the remainder produced by dividing every ordered pair (ai, aj) among the first k elements.

codeforcescompetitive-programmingdata-structuresmath
CF 1553D - Backspace

We are simulating a typing process where we scan a source string s from left to right. At each position, we either append the current character to an evolving text buffer or press backspace, which deletes the most recently added character if it exists.

codeforcescompetitive-programmingdpgreedystringstwo-pointers
CF 1553E - Permutation Shift

We start from the identity permutation, which is simply the numbers from 1 to n in order. Someone first rotates this array cyclically to the right by an unknown shift k, and then performs at most m arbitrary swaps of elements.

codeforcescompetitive-programmingbrute-forcecombinatoricsconstructive-algorithmsdfs-and-similardsugraphsmath
CF 1552H - Guess the Perimeter

We are dealing with a hidden axis-aligned rectangle whose corners lie on integer grid points inside a fixed 200 by 200 grid.

codeforcescompetitive-programmingbinary-searchinteractivenumber-theory
CF 1552C - Maximize the Intersections

We are given points placed around a circle in clockwise order. Some of these points are already connected by chords, and these initial chords never share endpoints.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgeometrygreedysortings
CF 1552E - Colors and Intervals

We are given a long line of positions from 1 to n·k, each position painted with one of n colors, and each color appears exactly k times. For every color i we must choose exactly one interval [ai, bi] such that both endpoints belong to positions colored i.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedysortings
CF 1551D1 - Domino (easy version)

We are given a rectangular board with $n$ rows and $m$ columns, containing $n cdot m$ unit cells. Since this product is even, the board can be fully tiled by dominoes, where each domino always covers exactly two adjacent cells sharing a side.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1551B1 - Wonderful Coloring - 1

We are given a string made of lowercase Latin letters. We want to select some of its positions and assign each selected position one of two colors, red or green, with three rules. First, every chosen position gets exactly one color, while some positions may remain unpainted.

codeforcescompetitive-programminggreedystrings
CF 1543A - Exciting Bets

We are given two non-negative integers, and we can move them in lockstep: every operation changes both values by exactly the same amount, either increasing both by one or decreasing both by one (as long as we do not go below zero).

codeforcescompetitive-programminggreedymathnumber-theory
CF 1543D1 - RPD and Rap Sheet (Easy Version)

We are playing an interactive game with a hidden number that always stays in the range from 0 to n − 1. We repeatedly submit guesses. If a guess is correct, the interaction ends immediately.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractivemath
CF 1542D - Priority Queue

We are given a sequence of operations that can either insert a value into a multiset or delete the smallest value currently present.

codeforcescompetitive-programmingcombinatoricsdpimplementationmathternary-search
CF 1542A - Odd Set

We are given a collection of numbers with even size, specifically 2n integers per test case. The task is to decide whether it is possible to partition these numbers into n disjoint pairs such that every pair consists of two numbers whose sum is odd.

codeforcescompetitive-programmingmath
CF 1538D - Another Problem About Dividing Numbers

We start with two numbers, and we are allowed to repeatedly “divide” either of them by some integer greater than one, as long as it divides cleanly.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1538E - Funny Substrings

We are given a very small “programming language” where variables store strings. Each variable is either assigned a literal string of length at most five, or defined as the concatenation of two previously defined variables.

codeforcescompetitive-programmingdata-structureshashingimplementationmatricesstrings
CF 1391D - 505

We are given a binary grid and we are allowed to flip cells from 0 to 1 or 1 to 0. The goal is to transform the grid so that every square submatrix whose side length is even contains an odd number of ones.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdpgreedyimplementation
CF 1391A - Suborrays

We are asked to construct a permutation of the numbers from 1 to n such that every contiguous segment behaves in a very specific way under the bitwise OR operation. For any subarray, we take all values inside it and compute their bitwise OR.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1389A - LCM Problem

We are given many independent ranges of integers. For each range $[l, r]$, we need to pick two different integers $x$ and $y$ inside this interval such that their least common multiple is also inside the same interval.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 1389C - Good String

We are given a string of digits and allowed to delete characters anywhere we like, preserving order of the remaining ones. The goal is to transform the string into a special form called “good”.

codeforcescompetitive-programmingbrute-forcedpgreedytwo-pointers
CF 1388A - Captain Flint and Crew Recruitment

We are given multiple independent queries, each asking whether a target number can be broken into four distinct positive integers.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1388D - Captain Flint and Treasure

We are given a directed structure over indices from 1 to n, where each index i has a value a[i] and a pointer b[i]. The pointer either leads to another index or is absent (represented by -1).

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsgreedyimplementationtrees
CF 1387B2 - Village (Maximum)

The village is a tree where each house is a node and each road is an edge of length one. Initially, every house has exactly one villager. We must reassign villagers so that every person moves to a different house, forming a permutation of nodes with no fixed points.

codeforcescompetitive-programming*specialdfs-and-similartrees
CF 1387A - Graph

We are given an undirected graph where every edge enforces a linear constraint between its endpoints. Each vertex must be assigned a real value, and every edge says exactly what the sum of its two endpoint values must be. Black edges force a sum of 1, red edges force a sum of 2.

codeforcescompetitive-programming*specialbinary-searchdfs-and-similardpmathternary-search
CF 1386A - Colors

We are interacting with a hidden system that has chosen an integer threshold $C$ between 1 and $N$. We can think of the numbers from 1 to $N$ as positions on a line, and every time we pick a position, we are effectively “dyeing” hair with that color.

codeforcescompetitive-programming*specialbinary-searchconstructive-algorithmsinteractive
CF 1386B - Mixture

We are maintaining a dynamic multiset of 3D vectors, each vector representing the amounts of salt, pepper, and garlic powder in a bottle.

codeforcescompetitive-programming*specialdata-structuresgeometrymathsortings
CF 1385F - Removing Leaves

We are working with a tree where vertices are gradually removed in rounds. In one round, we are allowed to pick a single internal vertex $v$ and remove exactly $k$ of its current leaf neighbors. A vertex counts as a leaf if it has degree one in the current remaining graph.

codeforcescompetitive-programmingdata-structuresgreedyimplementationtrees
CF 1385D - a-Good String

The task is to transform a given string into a very specific recursively defined structure centered around the letter 'a'.

codeforcescompetitive-programmingbitmasksbrute-forcedivide-and-conquerdpimplementation
CF 1385C - Make It Good

We are given an array and we are only allowed to delete a prefix, meaning we remove some number of elements from the front and keep the rest unchanged.

codeforcescompetitive-programminggreedy
CF 1384B2 - Koa and the Beach (Hard Version)

We are given a one-dimensional path from a shore to an island, where the sea between them is split into $n$ positions. Each position has a base depth $di$. Time progresses in discrete steps, and at each time the water level is uniformly shifted by a periodic tide function.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedyimplementation
CF 1384A - Common Prefixes

Stopped thinkingDo you like this personality?

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 1383D - Rearrange

We are given a complete permutation of numbers from 1 to $n cdot m$ arranged in an $n times m$ grid. From this grid we extract two small summaries: the set of row maxima and the set of column maxima.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraphsgreedysortings
CF 1383C - String Transformation 2

We are given two strings of equal length, built from a small alphabet of 20 letters. We start with string A and want to transform it into string B using a specific operation. One operation works like this: pick a letter x.

codeforcescompetitive-programmingbitmasksdpgraphstrees
CF 1382A - Common Subsequence

We are given two integer arrays, and we want to construct a third array that can be obtained by deleting elements from both of them. In other words, we are looking for a sequence of values that appears in both arrays while preserving order in each.

codeforcescompetitive-programmingbrute-force
CF 1381A1 - Prefix Flip (Easy Version)

We are given two binary strings of equal length. The goal is to transform the first string into the second using a very specific operation: pick a prefix, reverse it, and flip every bit inside it. Flipping means turning 0 into 1 and 1 into 0.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresstrings
CF 1381B - Unmerge

We are given a permutation of size $2n$. The task is to decide whether we can split the numbers into two disjoint sequences $a$ and $b$, each of length $n$, such that if we repeatedly simulate a specific “two-pointer merge” process starting from the heads of $a$ and $b$…

codeforcescompetitive-programmingdp
CF 1380G - Circular Dungeon

We are placing a multiset of values into a circular array of rooms. Each room contains exactly one item, and each item is either a regular chest with a reward value or a mimic that immediately stops the run when entered.

codeforcescompetitive-programminggreedymathprobabilities
CF 1380E - Merging Towers

We are given a set of numbered discs from 1 to n, where larger numbers represent larger discs. These discs are initially split across m towers, and each tower already has its discs stacked in decreasing order of size from bottom to top.

codeforcescompetitive-programmingdata-structuresdsuimplementationtrees
CF 1380B - Universal Solution

We are given a string describing a cyclic opponent strategy in a rock-paper-scissors game. The opponent does not adapt; instead, they choose moves according to a fixed circular string. If they start at some position, they follow the string in order and wrap around forever.

codeforcescompetitive-programminggreedy
CF 1379F2 - Chess Strikes Back (hard version)

We are working on a very large grid of size $2n times 2m$, but we only care about the white cells, those where the sum of coordinates is even. Among these white cells, some are dynamically toggled between available and unavailable across a sequence of updates.

codeforcescompetitive-programmingdata-structuresdivide-and-conquer
CF 1379A - Acacius and String

We are given a short string consisting of lowercase letters and question marks. Each question mark can later be replaced by any lowercase letter. After replacements, we want to end up with a string that contains the fixed pattern "abacaba" as a substring exactly once.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 1379C - Choosing flowers

We are choosing exactly $n$ flowers from $m$ available types, where each type can be used an unlimited number of times. The value of picking flowers is not linear per flower, instead each type behaves like a diminishing reward stream.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdfs-and-similardpgreedysortingstwo-pointers
CF 1375H - Set Merging

We are given a permutation of numbers from 1 to n, but the real object we care about is not the values themselves, it is their positions. Initially each position i forms a singleton set containing the value a[i].

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquer
CF 1375F - Integer Game

Three numbers represent the sizes of three piles of stones. The interaction alternates between us and the opponent.

codeforcescompetitive-programmingconstructive-algorithmsgamesinteractivemath
CF 1375E - Inversion SwapSort

We are given a sequence of numbers, and we are allowed to swap any two positions, but only if those two positions currently form an inversion in the original array. An inversion is simply a pair of indices where the left value is strictly larger than the right value.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1375A - Sign Flipping

Stopped thinking

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1375B - Neighbor Grid

We are given a grid of integers, but the final goal is not to preserve these values exactly. Instead, we are allowed to only increase values, and we want to transform the grid into a configuration where every positive cell behaves like a “node” whose value equals how many of…

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1374F - Cyclic Shifts Sorting

We are given an array and a very specific primitive operation: we can pick any position and rotate a block of three consecutive elements to the right. That means a local triple [x, y, z] becomes [z, x, y].

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsimplementationsortings
CF 1374E1 - Reading Books (easy version)

We are given a collection of books, each with a reading time and two independent preference flags, one for Alice and one for Bob.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 1373E - Sum of Digits

We are trying to construct the smallest non-negative integer $x$ such that if we take a short consecutive block of numbers starting at $x$, specifically $x, x+1, dots, x+k$, and sum the digit sums of all of them, the total equals a given target $n$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdpgreedy
CF 1373A - Donut Shops

We are comparing two different ways of buying the same number of donuts, and for each way we want to know when it becomes strictly cheaper than the other. In the first shop, the price is linear: buying $x$ donuts costs exactly $a cdot x$.

codeforcescompetitive-programminggreedyimplementationmath
CF 1373B - 01 Game

We are given a binary string and two players who alternately remove exactly two adjacent characters from it. Each move deletes a contiguous pair, so the string shrinks by 2 characters each turn.

codeforcescompetitive-programminggames
CF 1372A - Omkar and Completion

We are asked to construct an integer array of length n where every element is positive, does not exceed 1000, and satisfies a global restriction on sums: if we pick any three positions (they may coincide), the sum of two chosen elements is never equal to any element of the array.

codeforcescompetitive-programmingconstructive-algorithmsimplementation