brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1130A - Be Positive

We are given an array containing positive numbers, negative numbers, and possibly zeros. We need to choose a non-zero integer $d$ such that after dividing every element by $d$, at least half of the array elements are positive.

codeforcescompetitive-programmingimplementation
CF 1130B - Two Cakes

We are given a street with $2n$ consecutive houses, each house selling exactly one cake tier of a specific size between $1$ and $n$. Every size appears exactly twice. Two people start at house $1$.

codeforcescompetitive-programminggreedy
CF 1130C - Connect

We are given a square grid representing a planet with land and water. Alice starts at one land cell and wants to reach another land cell. She can only walk on land, moving orthogonally between adjacent cells. If a path exists naturally, she can reach her destination at zero cost.

codeforcescompetitive-programmingbrute-forcedfs-and-similardsu
CF 1131G - Most Dangerous Shark

We are given a long line of dominoes. Each domino has a height and a cost. When you push a domino, it falls either left or right, and during its fall it can trigger other dominoes if they lie within its reach.

codeforcescompetitive-programmingdata-structuresdptwo-pointers
CF 1131F - Asya And Kittens

We are given a set of kittens, each initially in its own cell arranged linearly in a row. Over the course of $n-1$ days, Asya records pairs of kittens who wanted to play together and removes the partition between their cells.

codeforcescompetitive-programmingconstructive-algorithmsdsu
CF 1131E - String Multiplication

We are asked to compute a property of a highly structured string operation. We are given a sequence of strings $p1, p2, dots, pn$, and we are asked to repeatedly apply Denis's string multiplication: multiplying $p1 cdot p2 cdot dots cdot pn$ in order.

codeforcescompetitive-programmingdpgreedystrings
CF 1131D - Gourmet choice

The problem asks us to assign positive integer scores to two sets of dishes tasted by Mr. Apple on two separate days. Each dish on the first day can be compared to every dish on the second day, and the comparison is either better, worse, or equal.

codeforcescompetitive-programmingdfs-and-similardpdsugraphsgreedy
CF 1131A - Sea Battle

The ship is formed by stacking two axis-aligned rectangles. The lower rectangle has width w1 and height h1. The upper rectangle has width w2 and height h2, and it starts immediately above the first rectangle with their left edges aligned.

codeforcescompetitive-programmingmath
CF 1131C - Birthday

We are asked to arrange a group of children in a circle such that the maximum height difference between any two adjacent children is as small as possible. The input provides the number of children n and an array of their heights.

codeforcescompetitive-programmingbinary-searchgreedysortings
CF 1131B - Draw!

We are given a sequence of partial observations of a football match. Each observation tells us the score at some moment in time, and these observations are already sorted by time.

codeforcescompetitive-programminggreedyimplementation
CF 1132G - Greedy Subsequences

We are given a long array of integers and a fixed window size. For every contiguous segment of length k, we are asked to simulate a very specific process that builds a subsequence of indices.

codeforcescompetitive-programmingdata-structuresdptrees
CF 1132F - Clear the String

We have a string of lowercase letters. In one operation, we may choose any contiguous block whose characters are all the same and remove it. After removal, the remaining parts of the string join together.

codeforcescompetitive-programmingdp
CF 1132D - Stressful Training

We have a contest with n students, each with a laptop that starts with some initial battery ai and consumes bi units of charge per minute. The contest lasts k minutes.

codeforcescompetitive-programmingbinary-searchgreedy
CF 1132E - Knapsack

We are given a multiset of items where every item has a weight between 1 and 8 inclusive. The number of items of each weight is extremely large, but only their counts matter, not their identities.

codeforcescompetitive-programmingdfs-and-similardpgreedy
CF 1132C - Painting the Fence

We have a fence with n sections numbered from 1 to n. Each painter covers one continuous interval [li, ri]. Originally all q painters are available, but we are forced to dismiss exactly two of them and keep the remaining q - 2.

codeforcescompetitive-programmingbrute-force
CF 1132B - Discounts

We have a set of chocolate bars, each with its own price. The shopper wants all the bars but has a selection of discount coupons. Each coupon allows buying a fixed number of bars, but within that selection, the cheapest bar is free.

codeforcescompetitive-programminggreedysortings
CF 1132A - Regular Bracket Sequence

We are given four types of bracket strings, each of length two: "((", "()", ")(", and "))". The input provides counts of how many of each type we have.

codeforcescompetitive-programminggreedyimplementation
CF 1133F2 - Spanning Tree with One Fixed Degree

We are given a connected undirected simple graph and asked to construct a spanning tree using only existing edges. The additional constraint is that vertex 1 must have degree exactly D in the chosen tree.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardsugraphsgreedy
CF 1133F1 - Spanning Tree with Maximum Degree

We are given a connected undirected graph and must select exactly $n-1$ of its edges so that they form a spanning tree. Among all possible spanning trees, we want one whose largest vertex degree is as large as possible. A spanning tree connects all vertices without cycles.

codeforcescompetitive-programminggraphs
CF 1133D - Zero Quantity Maximization

We are given two arrays of integers, a and b, each with n elements. We are asked to construct a new array c using a single real number d such that each element ci equals d ai + bi. Our goal is to choose d to maximize the number of zeros in c.

codeforcescompetitive-programminghashingmathnumber-theory
CF 1133E - K Balanced Teams

We have a list of students, each with a programming skill level. The task is to divide these students into at most k teams so that the total number of students included is maximized.

codeforcescompetitive-programmingdpsortingstwo-pointers
CF 1133B - Preparation for International Women's Day

We are given a set of candy boxes, each containing a certain number of candies, and a number k representing the group size for which we want to prepare gifts. A gift consists of exactly two boxes, and the sum of candies in the two boxes must be divisible by k.

codeforcescompetitive-programmingmathnumber-theory
CF 1133C - Balanced Team

We have a list of students, each with a programming skill score. The task is to form the largest possible team such that the difference between the highest-skilled and lowest-skilled members does not exceed 5. In other words, for any team of size $k$, if the skills are $s1, s2, .

codeforcescompetitive-programmingsortingstwo-pointers
CF 1133A - Middle of the Contest

The task is to find the exact midpoint of a contest given its start and end times in hours and minutes. The input gives the start time as h1:m1 and the end time as h2:m2.

codeforcescompetitive-programmingimplementation
CF 1136E - Nastya Hasn't Written a Legend

We have an array a and another array k. The array always satisfies a monotonic-type constraint: $$a{i+1} ge ai + ki$$ for every adjacent pair. There are two operations. The first operation increases one position a[i] by some value x.

codeforcescompetitive-programmingbinary-searchdata-structures
CF 1136D - Nastya Is Buying Lunch

The queue is fixed initially, and the last person in the queue is Nastya. Some ordered pairs $(u,v)$ are given. A pair means that whenever pupil $u$ stands immediately in front of pupil $v$, those two pupils are willing to swap places.

codeforcescompetitive-programminggreedy
CF 1136B - Nastya Is Playing Computer Games

There are n manholes arranged in a line. Each manhole initially contains exactly one stone on top of it and one coin underneath it. Nastya starts at manhole k. A coin can only be collected when the current manhole has no stones on it.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1136C - Nastya Is Transposing Matrices

We are given two matrices of the same size, A and B. The allowed operation is surprisingly powerful: we may choose any square submatrix inside A and transpose it. Transposition swaps positions relative to the square's main diagonal.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1136A - Nastya Is Reading a Book

The book is divided into consecutive chapters. Each chapter occupies a continuous range of pages, and every page belongs to exactly one chapter. Nastya has already read pages 1 through k - 1. Page k is the first page she has not read yet.

codeforcescompetitive-programmingimplementation
CF 1137E - Train Car Selection

We are asked to simulate a train that grows and whose car values evolve over time. Initially, there are $n$ cars numbered from the head.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1137D - Cooperative Game

We are asked to coordinate ten players on a secret graph consisting of a directed path leading to a cycle. The path has length t, ending at the start of a cycle of length c, which represents a scenic lake road. Every vertex has exactly one outgoing edge.

codeforcescompetitive-programmingconstructive-algorithmsinteractivenumber-theory
CF 1137F - Matches Are Not a Child's Play

We are given a tree of n vertices, each with a unique integer priority initially equal to its label. We can imagine burning the tree in a particular order: repeatedly remove the leaf with the smallest priority until no vertices remain.

codeforcescompetitive-programmingdata-structurestrees
CF 1137B - Camp Schedule

We are given two binary strings. The first string s is not the schedule we must output directly. Instead, it acts as a multiset of characters.

codeforcescompetitive-programminggreedyhashingstrings
CF 1137A - Skyscrapers

We are given a city laid out as a grid of size $n times m$, where each cell represents an intersection containing a skyscraper of a certain height.

codeforcescompetitive-programmingimplementationsortings
CF 1137C - Museums Tour

We are asked to plan a tour starting from city 1 on the first day of a week, aiming to visit as many distinct museums as possible. Each city has exactly one museum, and museums have a weekly schedule specifying on which day of the week they are open.

codeforcescompetitive-programmingdpgraphsimplementation
CF 1138B - Circus

We have a troupe of n circus artists, where n is guaranteed to be even. Each artist may have the skill of being a clown, an acrobat, both, or neither.

codeforcescompetitive-programmingbrute-forcegreedymathstrings
CF 1138A - Sushi for Two

We are given a row of sushi pieces, where each piece is either type 1 or type 2. We want to choose one contiguous segment of this row. A segment is valid if it consists of two consecutive blocks of different sushi types, and both blocks have the same size.

codeforcescompetitive-programmingbinary-searchgreedyimplementation
CF 1139D - Steps to One

We repeatedly choose a random integer from 1 to m, independently and uniformly. After each choice, we look at the gcd of all numbers chosen so far. The process stops as soon as this gcd becomes 1. We must compute the expected number of chosen integers.

codeforcescompetitive-programmingdpmathnumber-theoryprobabilities
CF 1139E - Maximize Mex

Each student belongs to exactly one club and has a potential value. On a given day, some students have already left their clubs permanently. From the remaining students, we may choose at most one student from each club. The chosen students form the contest team.

codeforcescompetitive-programmingflowsgraph-matchingsgraphs
CF 1139F - Dish Shopping

We are asked to determine how many dishes each person in a city can buy given multiple constraints. Each dish has a price, a minimum standard requirement, and a beauty value. Each person has an income and a preferred beauty.

codeforcescompetitive-programmingdata-structuresdivide-and-conquer
CF 1139C - Edgy Trees

We have a tree whose edges are colored either red (0) or black (1). We must count how many sequences of length k consisting of tree vertices are "good". For a sequence [a₁, a₂, ...

codeforcescompetitive-programmingdfs-and-similardsugraphsmathtrees
CF 1139B - Chocolates

We have a set of chocolate types, each with a limited stock. Our goal is to pick a number of chocolates from each type so that the total number of chocolates is maximized.

codeforcescompetitive-programminggreedyimplementation
CF 1139A - Even Substrings

We are given a string of digits from 1 to 9. Our task is to count how many substrings, defined by any contiguous range of indices, represent even numbers. A substring is even if its last digit is even, since the number’s parity is determined entirely by the last digit.

codeforcescompetitive-programmingimplementationstrings
CF 1140G - Double Tree

We are given a graph on $2n$ vertices that is highly structured: vertices are split into odd and even indices, and each side forms a tree with the same shape.

codeforcescompetitive-programmingdata-structuresdivide-and-conquershortest-pathstrees
CF 1140F - Extending Set of Points

We are maintaining a dynamic set of grid points on a large integer lattice. After each insertion or deletion, we are asked to compute not the size of the current set, but the size of its closure under a specific completion rule.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdsu
CF 1140E - Palindrome-less Arrays

We are asked to count the number of arrays we can construct from a partially specified array of length n, where some elements are missing and represented by -1. Each -1 can be replaced by any integer from 1 to k.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerdp
CF 1140D - Minimum Triangulation

We are given a regular polygon with n vertices labeled 1 through n in counter-clockwise order. The goal is to divide this polygon into non-overlapping triangles so that the sum of the “weights” of all triangles is minimized.

codeforcescompetitive-programmingdpgreedymath
CF 1140B - Good String

We are given a string made only of two symbols, and <. We are allowed to repeatedly perform operations that “push deletions” in a local direction: choosing a removes the character immediately to its right, while choosing a < removes the character immediately to its left.

codeforcescompetitive-programmingimplementationstrings
CF 1140C - Playlist

Each song has two attributes: its length t and its beauty b. If we choose some subset of songs, its score is $$(text{sum of lengths}) times (text{minimum beauty})$$ We may choose at most k songs, and we want the maximum possible score.

codeforcescompetitive-programmingbrute-forcedata-structuressortings
CF 1140A - Detective Book

Ivan’s detective book is structured such that each page introduces a mystery, and the solution to that mystery is revealed on a later page. Concretely, we have a list of integers where the $i$-th integer $ai$ tells us the page that resolves the mystery introduced on page $i$.

codeforcescompetitive-programmingimplementation
CF 1141G - Privatization of Roads in Treeland

We are given a tree with $n$ vertices and $n-1$ edges. Every edge must be assigned a company number. A city is considered good if all roads incident to it belong to different companies. A city becomes bad if at least two incident roads receive the same company.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdfs-and-similargraphsgreedytrees
CF 1141F2 - Same Sum Blocks (Hard)

We are given a one-dimensional array of integers, and we want to split it into contiguous subarrays, which we call blocks. Each block must have the same sum of its elements, and no two blocks can overlap.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1141D - Colored Boots

We are given two sets of boots: one left set and one right set, each containing exactly $n$ boots. Each boot has a color, either a specific lowercase letter or a question mark representing an unknown color.

codeforcescompetitive-programminggreedyimplementation
CF 1141F1 - Same Sum Blocks (Easy)

We are given an array of integers and may choose several contiguous subarrays, called blocks. Every chosen block must have exactly the same sum, and no two chosen blocks may overlap.

codeforcescompetitive-programminggreedy
CF 1141E - Superhero Battle

We are given a monster with an initial health value and a repeating damage pattern applied once per minute. The pattern has length n, and after the last minute we immediately loop back to the first minute and continue forever.

codeforcescompetitive-programmingmath
CF 1141A - Game 23

We start with a number and want to reach a larger target number. The only allowed operation is multiplying the current value by 2 or by 3. The task is to determine how many operations are needed, or report that the transformation cannot be done.

codeforcescompetitive-programmingimplementationmath
CF 1141C - Polycarp Restores Permutation

We are given a sequence of differences between consecutive elements of an unknown permutation. More precisely, if the permutation is $p1, p2, dots, pn$, we are given an array $q$ of length $n-1$ such that each $qi = p{i+1} - pi$.

codeforcescompetitive-programmingmath
CF 1141B - Maximal Continuous Rest

We are given a binary sequence representing a single day, where each position corresponds to an hour. A value of 1 means Polycarp is resting during that hour, while 0 means he is working.

codeforcescompetitive-programmingimplementation
CF 1142E - Pink Floyd

We are given a complete undirected graph on $n$ nodes, but each edge is assigned a direction, making it a tournament. A subset of these edges are colored pink and their directions are known. The remaining edges are green, and their directions are initially unknown.

codeforcescompetitive-programminggraphsinteractive
CF 1142D - Foreigner

We are given a long digit string that was formed by writing several integers back to back without separators. Each contiguous substring of this string can be interpreted as an integer (with no leading zeros unless the substring is exactly "0", though here the input guarantees…

codeforcescompetitive-programmingdp
CF 1142B - Lynyrd Skynyrd

We are given a fixed permutation of numbers from 1 to n. Separately, we have a longer array whose elements also lie in the range 1 to n, but may repeat. The task is to answer many queries on subsegments of this array.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpmathtrees
CF 1142C - U2

We are given a set of points on a two-dimensional plane with integer coordinates. For each pair of points that do not share the same x-coordinate, we can uniquely define a parabola of the form $y = x^2 + bx + c$ that passes through both points.

codeforcescompetitive-programminggeometry
CF 1142A - The Beatles

We are given a circular route that passes through $n cdot k$ cities arranged consecutively. Among these, there are $n$ fast food restaurants evenly spaced such that the distance along the circle between any two consecutive restaurants is $k$ kilometers.

codeforcescompetitive-programmingbrute-forcemath
CF 1143B - Nirvana

We are asked to find, for a given integer $n$, the largest product of digits that any number from 1 to $n$ can have. In other words, imagine iterating through all numbers from 1 up to $n$ and multiplying the digits of each number; we want the maximum such product.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1143C - Queen

We are given a rooted tree with n vertices. Each vertex has a parent pi and a respect indicator ci. The root is special: it has pi = -1 and ci = 0.

codeforcescompetitive-programmingdfs-and-similartrees
CF 1143A - The Doors

The problem can be restated as follows. Mr. Black has a house with two sets of doors, each leading to a separate exit: left and right. Each door is initially closed, and we know the exact sequence in which Mr. Black opens them.

codeforcescompetitive-programmingimplementation
CF 1144D - Equalize Them All

We are given a sequence of integers arranged in a line. In one move, we pick two neighboring positions and use the difference between their values to either increase or decrease one of them by exactly that difference.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1144G - Two Merged Sequences

We are given a single sequence, and we are told that it was originally formed by taking two hidden sequences and interleaving them.

codeforcescompetitive-programmingdpgreedy
CF 1144F - Graph Without Long Directed Paths

We are given a connected undirected graph with n vertices and m edges. Our task is to assign a direction to every edge so that the resulting directed graph does not contain any path of length two or more.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 1144E - Median String

We are asked to find the median string between two given strings of the same length, s and t, using lexicographical ordering. Both strings consist only of lowercase Latin letters, and s is guaranteed to be strictly smaller than t.

codeforcescompetitive-programmingbitmasksmathnumber-theorystrings
CF 1144C - Two Shuffled Sequences

We are given a multiset of integers that was created by taking two sequences, one strictly increasing and one strictly decreasing, merging all their elements together, and then shuffling the result. The original order inside the merged array is lost.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1144B - Parity Alternated Deletions

We are given a sequence of integers, and we are allowed to remove elements one by one under a parity constraint that depends on the previous deletion. The first removed element can be anything.

codeforcescompetitive-programminggreedyimplementationsortings
CF 1144A - Diverse Strings

We are given several short strings, and for each one we need to decide whether it forms a single continuous block of the alphabet without any gaps or repetition. Think of the lowercase alphabet as a line from ‘a’ to ‘z’.

codeforcescompetitive-programmingimplementationstrings
CF 1145F - Neat Words

We are given a single string of uppercase letters with length between 1 and 10. The task is to determine whether this string is "neat." A neat word, in this context, is defined as one where no letter appears more than once at even positions or more than once at odd positions.

codeforcescompetitive-programming*special
CF 1145G - AI Takeover

This is an interactive game against a fixed but unknown opponent program. The opponent chooses one deterministic strategy at the beginning of the test and sticks to it for all 20 rounds.

codeforcescompetitive-programming*specialinteractive
CF 1145D - Pigeon d'Or

We are given a small array of integers, each between 1 and 32, and we are asked to find a certain integer that represents the maximum number of consecutive elements that satisfy a bitwise property.

codeforcescompetitive-programming*specialimplementation
CF 1145E - Fourier Doodles

We are given a small supervised learning task disguised as a programming problem. There are 50 grayscale images indexed from 1 to 50. For the first 20 images, we are given binary labels indicating whether each image is considered a “Fourier doodle” or not.

codeforcescompetitive-programming
CF 1145C - Mystery Circuit

We are given a single integer a between 0 and 15. This integer represents a configuration of a simple 4-bit circuit, where each bit can be either 0 or 1. The task is to compute an output integer based on a mysterious internal rule of the circuit.

codeforcescompetitive-programmingbitmasksbrute-force
CF 1145B - Kanban Numbers

We are asked to determine whether a given number can be represented as the sum of any number of integers equal to 4 or 7. The input is a single integer $a$ between 1 and 99, and the output is either "YES" if such a representation exists, or "NO" otherwise.

codeforcescompetitive-programming*specialbrute-force
CF 1145A - Thanos Sort

We start with an array whose length is a power of two. The allowed operation is very unusual: whenever the current array is not sorted in non-decreasing order, we may delete either its left half or its right half. After that, we repeat the same process on the remaining half.

codeforcescompetitive-programming*specialimplementation
CF 1146H - Satanic Panic

We are given a set of $n$ points on a 2D plane, with the guarantee that no three points are collinear. From these points, we want to count the number of 5-point subsets that can form a pentagram-a star-shaped configuration where the points are connected in a specific…

codeforcescompetitive-programmingdpgeometry
CF 1146F - Leaf Partition

We are given a rooted tree with n nodes, where node 1 is the root. Each node other than the root has a parent specified. A leaf is any node without children.

codeforcescompetitive-programmingdptrees
CF 1146G - Zoning Restrictions

We are asked to assign heights to houses along a street in order to maximize total profit. The street has n available positions, each of which can host a house with an integer height between 0 and h. The profit from a house of height a is a^2. There are m city restrictions.

codeforcescompetitive-programmingdpflowsgraphs
CF 1146D - Frog Jumping

A frog starts at position 0 on a number line. From any position, it can move forward by adding a or move backward by subtracting b. However, during the process of exploring what is reachable, we only allow it to stay within the segment [0, x] when computing f(x).

codeforcescompetitive-programmingdfs-and-similarmathnumber-theory
CF 1146E - Hot is Cold

We are given an array of integers and a series of queries. Each query instructs us to flip the sign of numbers in the array that satisfy a comparison: either all numbers greater than a threshold or all numbers less than a threshold.

codeforcescompetitive-programmingbitmasksdata-structuresdivide-and-conquerimplementation
CF 1146C - Tree Diameter

We are asked to determine the diameter of an unknown weighted tree. The tree has n nodes connected by n-1 edges, each with a positive integer weight at most 100. We do not have direct access to the edges.

codeforcescompetitive-programmingbitmasksgraphsinteractive
CF 1147F - Zigzag Game

The game is played on a complete bipartite graph with two equal groups of vertices. Every vertex on the left side connects to every vertex on the right side, and each such edge has a unique weight.

codeforcescompetitive-programminggamesinteractive
CF 1147E - Rainbow Coins

We are given a hidden assignment of colors to numbered coins, where each coin is exactly one of three colors. The goal is to partition the coins into three groups so that each group contains coins of a single color, but we do not know the colors directly.

codeforcescompetitive-programminginteractive
CF 1147D - Palindrome XOR

We are given a binary string pattern s consisting of '1', '0', and '?', with the guarantee that the first character is '1'.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 1147A - Hide and Seek

We are working on a line of $n$ cells where a token starts somewhere and may move over time. Bob asks a sequence of queries, each query naming a cell, and Alice must always answer “NO” to every query.

codeforcescompetitive-programminggraphs
CF 1147C - Thanos Nim

We are asked to analyze a two-player game played on an array of piles, each containing some number of stones. There are $n$ piles, and $n$ is guaranteed to be even.

codeforcescompetitive-programminggames
CF 1147B - Chladni Figure

The problem gives a rectangular grid of characters representing a pattern on a metal plate, where each cell contains either a . (empty) or a (filled). The task is to find the smallest rectangle that contains all the characters.

codeforcescompetitive-programmingbrute-forcestrings
CF 1148H - Holy Diver

We are asked to maintain an array that grows dynamically. On each operation, we append a new element to the array and immediately count the number of contiguous subarrays (segments) within a given range [l, r] whose mex equals a given number k.

codeforcescompetitive-programmingdata-structures
CF 1148G - Gold Experience

We are given an array of integers placed on vertices of a complete set of labels. Between any two vertices we implicitly define an undirected edge if the two associated values share a nontrivial common divisor, meaning their gcd is greater than one.

codeforcescompetitive-programmingconstructive-algorithmsgraphsmathnumber-theoryprobabilities
CF 1148C - Crazy Diamond

We are given a permutation of the numbers from 1 to $n$, where $n$ is guaranteed to be even. A permutation means each number appears exactly once in the array. The task is to sort this permutation in ascending order.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1148F - Foo Fighters

We are given a collection of objects, each contributing a signed value and a binary mask. We must choose a positive integer s. Once s is fixed, each object is either kept as-is or flipped in sign depending on a parity condition computed from s and its mask.

codeforcescompetitive-programmingbitmasksconstructive-algorithms
CF 1148E - Earth Wind and Fire

We are given two multisets of integer positions on a number line. One multiset describes where stones start, the other describes where we want them to end.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortingstwo-pointers
CF 1148A - Another One Bites The Dust

We are given three pools of building blocks. There are a pieces of the letter string "a", b pieces of "b", and c pieces of "ab". We are allowed to select any subset of these blocks and concatenate them in any order we want.

codeforcescompetitive-programminggreedy
CF 1148D - Dirty Deeds Done Dirt Cheap

We are given a collection of $n$ disjoint pairs of integers. Every integer from $1$ to $2n$ appears exactly once across all pairs, so each number belongs to exactly one pair and there is no overlap.

codeforcescompetitive-programminggreedysortings
CF 1148B - Born This Way

We are given two sorted timelines of flights forming a mandatory two-leg journey. A passenger first chooses a flight from A to B, spending a fixed travel time, and then immediately connects to a flight from B to C, again with a fixed travel time.

codeforcescompetitive-programmingbinary-searchbrute-forcetwo-pointers