#sortings
CF 1267I - Intriguing Selection
CF 1267I - Intriguing Selection Rating: 2600 Tags: brute force, constructive algorithms, implementation, interactive, sortings Solve time: 2m 16s Verified: no Solution Problem Understanding We are given a hidden set of $2n$ distinct values, one per player, and we can only compare two players at a time and learn which one is stronger. The goal is not to fully reconstruct the ranking, but to identify exactly which $n$ players belong...
CF 958E2 - Guard Duty (medium) Rating: 2200 Tags: binary search, dp, greedy, sortings Model: gpt-5-3-mini Solve time: 3m 26s Verified: no (0/1 samples) Share: https://chatgpt.com/share/6a339e66-d274-83ec-9c8a-9aa9396149de Solution Problem Understanding We are given a strictly increasing sequence of time moments when Heidi temporarily leaves hyperspace. These moments are the only valid endpoints at which meetings can begin or end. Heidi must organize exactly $K$ disjoint meetings, where each meeting is defined...
CF 960B - Minimize the error
CF 960B - Minimize the error Rating: 1500 Tags: data structures, greedy, sortings Solve time: 1m 14s Verified: yes Solution Problem Understanding We are working with two integer arrays of equal length. Each position contributes independently to a total “error”, where the error of an index is the square of the difference between the two values at that index. The total cost is the sum of these squared differences over...
CF 967B - Watering System
CF 967B - Watering System Rating: 1000 Tags: math, sortings Solve time: 1m 28s Verified: yes Solution Problem Understanding We are given a system of pipe holes, each hole having a fixed size that determines how much water it can drain when water is poured into the system. Arkady pours a fixed amount of water, but only one hole, the first one, is considered useful to him. His goal is...
CF 984A - Game
CF 984A - Game Rating: 800 Tags: sortings Solve time: 1m 30s Verified: yes Solution Problem Understanding We are given a list of integers placed on a board. Two players alternate turns removing exactly one number from the board. After exactly $n-1$ removals, only a single number remains, and that number is the outcome of the game. The players have opposing goals. The first player removes numbers in a way...
CF 1025A - Doggo Recoloring
CF 1025A - Doggo Recoloring Rating: 900 Tags: implementation, sortings Solve time: 2m 13s Verified: yes Solution Problem Understanding We are given a string representing the colors of a line of puppies, where each character is a color from 'a' to 'z'. The goal is to determine whether we can transform this string so that all characters become the same, using a very specific operation. The operation allows us to...
CF 1039C - Network Safety
CF 1039C - Network Safety Rating: 2200 Tags: dfs and similar, dsu, graphs, math, sortings Solve time: 8m 24s Verified: yes Solution Problem Understanding 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. A virus is...
CF 1725F - Field Photography
CF 1725F - Field Photography Rating: 2100 Tags: bitmasks, data structures, sortings Solve time: 2m 55s Verified: no Solution Problem Understanding Each row initially contains a contiguous block of contestants placed on an extremely large integer line of columns. Row $i$ occupies every position from $L_i$ to $R_i$, so geometrically each row is just a closed interval. We are allowed to shift an entire row left or right by any...
CF 1558F - Strange Sort
CF 1558F - Strange Sort Rating: 3300 Tags: data structures, sortings Solve time: 5m 6s Verified: no Solution Problem Understanding 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. On odd-numbered iterations we compare and possibly swap positions (1,2), (3,4), (5,6),...
CF 1386B - Mixture
CF 1386B - Mixture Rating: 2900 Tags: *special, data structures, geometry, math, sortings Solve time: 7m 15s Verified: no Solution Problem Understanding We are maintaining a dynamic multiset of 3D vectors, each vector representing the amounts of salt, pepper, and garlic powder in a bottle. After each update, either adding or removing a bottle, we must determine the smallest number of available bottles whose positive linear combination can produce a...
CF 1214E - Petya and Construction Set
CF 1214E - Petya and Construction Set Rating: 2000 Tags: constructive algorithms, graphs, math, sortings, trees Solve time: 2m 50s Verified: no Solution Problem Understanding We are asked to build a graph on $2n$ labeled vertices using exactly $2n-1$ edges. Since a connected graph with $2n$ vertices and $2n-1$ edges is necessarily a tree, the construction is really about designing a tree on these labeled nodes. The vertices come in...
CF 1209E2 - Rotate Columns (hard version)
CF 1209E2 - Rotate Columns (hard version) Rating: 2500 Tags: bitmasks, dp, greedy, sortings Solve time: 4m 14s Verified: no Solution Problem Understanding We are given a grid with a small number of rows and a potentially large number of columns. The only operation allowed is to take any single column and rotate it cyclically any number of times. After performing these rotations independently for each column, we look at...
CF 1773E - Easy Assembly
CF 1773E - Easy Assembly Rating: 1400 Tags: greedy, sortings Solve time: 2m 6s Verified: yes Solution Problem Understanding We are given several vertical stacks of uniquely numbered blocks. Each stack is ordered from top to bottom, and we are allowed to physically reorganize these blocks using two operations: we can cut a stack into two by taking a prefix or suffix segment and turning it into a new stack,...
CF 1726G - A Certain Magical Party
CF 1726G - A Certain Magical Party Rating: 3300 Tags: combinatorics, data structures, greedy, sortings Solve time: 5m 44s Verified: no Solution Problem Understanding We are given a group of $n$ people, each starting with a happiness value $a_i$ and a binary personality flag $b_i$. We choose a permutation, which represents the order in which they speak. When a person speaks, they look at everyone else’s current happiness values and...
CF 1654F - Minimal String Xoration
CF 1654F - Minimal String Xoration Rating: 2800 Tags: bitmasks, data structures, divide and conquer, greedy, hashing, sortings, strings Solve time: 2m 42s Verified: yes Solution Problem Understanding We are given a string whose length is a power of two, indexed from 0 to $2^n - 1$. The key operation allowed is a global reindexing of the string using bitwise XOR with a fixed mask $j$. In other words, we...
CF 1561A - Simply Strange Sort
CF 1561A - Simply Strange Sort Rating: 800 Tags: brute force, implementation, sortings Solve time: 2m 40s Verified: yes Solution Problem Understanding We are given a permutation, meaning an array containing every integer from 1 to n exactly once. The process repeatedly applies a deterministic “strange bubble pass” operation, but with a twist: odd-numbered rounds compare adjacent pairs starting from index 1, 3, 5, and even-numbered rounds start from index...
CF 1320A - Journey Planning Rating: 1400 Tags: data structures, dp, greedy, math, sortings Model: gpt-5-5 Solve time: 4m 27s Verified: yes (1/1 samples) Share: https://chatgpt.com/share/6a2de6ec-99fc-83ec-9276-106005ae8eca Solution Problem Understanding We are given a line of cities, each with an index from left to right and an associated beauty value. We need to choose a sequence of cities to visit such that indices strictly increase. The key restriction is that consecutive...
CF 1322B - Present Rating: 2100 Tags: binary search, bitmasks, constructive algorithms, data structures, math, sortings Model: gpt-5-3-mini Solve time: 1m 28s Verified: yes (1/1 samples) Share: https://chatgpt.com/share/6a2deae4-fc9c-83ec-aeba-66f8cbbf4563 Solution Problem Understanding We are given an array of integers, and we consider every unordered pair of distinct elements. For each pair, we compute their sum. After collecting all these pairwise sums, instead of summing or minimizing them, we combine them using...
CF 1184B1 - The Doctor Meets Vader (Easy)
CF 1184B1 - The Doctor Meets Vader (Easy) Rating: 1400 Tags: binary search, sortings Solve time: 5m 28s Verified: yes Solution Problem Understanding Each spaceship has an attack power. Each empire base has a defense value and a gold amount. A spaceship can destroy every base whose defense is not greater than the spaceship's attack power. Since destroying a base gives all of its gold, the answer for a spaceship...
CF 1121A - Technogoblet of Fire
CF 1121A - Technogoblet of Fire Rating: 1100 Tags: implementation, sortings Solve time: 1m 6s Verified: yes Solution Problem Understanding We are given a set of students, each belonging to a school, and each with a power rating. The tournament rule is simple: only the strongest student from each school gets selected. Arkady wants to ensure that a chosen set of k students are selected. Some of these students may...
CF 1184B2 - The Doctor Meets Vader (Medium)
CF 1184B2 - The Doctor Meets Vader (Medium) Rating: 2200 Tags: flows, graph matchings, graphs, shortest paths, sortings Solve time: 2m 6s Verified: yes Solution Problem Understanding The galaxy is a small graph of planets connected by wormholes, where distance between planets is measured as the minimum number of edges in this graph. On top of this infrastructure, there are two kinds of actors: empire ships and rebel bases. Each...
CF 1209E1 - Rotate Columns (easy version)
CF 1209E1 - Rotate Columns (easy version) Rating: 2000 Tags: bitmasks, brute force, dp, greedy, sortings Solve time: 1m 58s Verified: yes Solution Problem Understanding We are given a matrix with n rows and m columns, where each entry is a positive integer. We can pick any column and rotate it cyclically any number of times. After performing such rotations, we consider each row and take the maximum value in...
CF 1214F - Employment
CF 1214F - Employment Rating: 2700 Tags: greedy, sortings Solve time: 2m 40s Verified: yes Solution Problem Understanding We have two multisets of points on a circle of length m . The first set contains the office locations. Office i is located in city a[i] . The second set contains the candidates. Candidate j lives in city b[j] . Every office must receive exactly one candidate and every candidate must...
CF 1305A - Kuroni and the Gifts
CF 1305A - Kuroni and the Gifts Rating: 800 Tags: brute force, constructive algorithms, greedy, sortings Solve time: 1m 48s Verified: no Solution Yes, the inequality $\nu(n) \le 2^{l(n) - \lambda(n)}$ holds for all positive integers $n$. Consider an addition chain of minimal length $l(n)$ and let $\lambda(n)$ be the length of a shortest chain consisting only of doubling steps. Each nondoubling step can at most double the number of...
CF 1320C - World of Darkraft: Battle for Azathoth
CF 1320C - World of Darkraft: Battle for Azathoth Rating: 2000 Tags: brute force, data structures, sortings Solve time: 2m 48s Verified: no Solution Yes, the inequality $\nu(n) \le 2^{l(n) - \lambda(n)}$ holds for all positive integers $n$. Consider an addition chain of minimal length $l(n)$ and let $\lambda(n)$ be the length of a shortest chain consisting only of doubling steps. Each nondoubling step can at most double the number...
CF 1402B - Roads
CF 1402B - Roads Rating: 2900 Tags: *special, geometry, sortings Solve time: 5m 59s Verified: no Solution Diagnosis The crash happens immediately on this line: n, m = map(int, input().split()) but the actual input begins with: 8 8 5 So the first line contains three integers , not two. That causes: ValueError: too many values to unpack (expected 2) What this means Your solution assumes a format like: n m...
CF 1402A - Fancy Fence
CF 1402A - Fancy Fence Rating: 1800 Tags: *special, data structures, dsu, implementation, math, sortings Solve time: 1m 59s Verified: no Solution Problem Understanding We are given a fence composed of $N$ rectangular sections placed side by side. Each section $i$ has a width $w_i$ and a height $h_i$. Our task is to count all axis-aligned rectangles that can be formed entirely on top of these sections. A rectangle must...
CF 1403A - The Potion of Great Power
CF 1403A - The Potion of Great Power Rating: 2400 Tags: *special, 2-sat, binary search, data structures, graphs, interactive, sortings, two pointers Solve time: 2m 3s Verified: no Solution Problem Understanding We have a dynamic friendship network among N shamans, each living at a specific altitude H[i] . Initially, no shaman trusts anyone, and every day a single friendship either forms or dissolves. Each shaman can trust at most D...
CF 1443C - The Delivery Dilemma
CF 1443C - The Delivery Dilemma Rating: 1400 Tags: binary search, greedy, sortings Solve time: 5m 13s Verified: yes Solution Problem Understanding In this problem, Petya wants to get all his birthday dishes in the minimum amount of time. For each dish, he can either pick it up himself from a restaurant, taking b_i minutes, or order a delivery, which will arrive in a_i minutes. All couriers start delivering at...
CF 1443B - Saving the City
CF 1443B - Saving the City Rating: 1300 Tags: dp, greedy, math, sortings Solve time: 1m 28s Verified: yes Solution Problem Understanding We are given a city represented as a line of buildings, each of which may or may not have a mine. The city map is a string of zeros and ones, where "1" indicates a mine and "0" indicates a safe building. The sapper has two operations: he...
CF 1468D - Firecrackers
CF 1468D - Firecrackers Rating: 1700 Tags: binary search, sortings Solve time: 3m 41s Verified: no Solution Problem Understanding A hooligan and a guard stand in a one dimensional corridor. Every second, the hooligan acts first, then already dropped firecrackers may explode, then the guard moves one step toward the hooligan. The hooligan owns several firecrackers. A firecracker with value s explodes exactly s seconds after it is lit. The...
CF 1500D - Tiles for Bathroom
CF 1500D - Tiles for Bathroom Rating: 2900 Tags: data structures, sortings, two pointers Solve time: 1m 16s Verified: yes Solution Problem Understanding We are given an $n \times n$ grid representing a tile stand, where each cell contains a tile of a certain color. Kostya wants to know, for each possible subsquare size $k$, how many $k \times k$ subsquares contain at most $q$ distinct colors. A subsquare is...
CF 1501B - Napoleon Cake
CF 1501B - Napoleon Cake Rating: 900 Tags: dp, implementation, sortings Solve time: 2m 15s Verified: no Solution Problem Understanding We build the cake layer by layer. After placing the i -th layer, we pour a[i] units of cream onto the top. That cream spreads downward and covers the top a[i] layers currently present. If there are fewer than a[i] layers, every existing layer becomes covered. For each layer, we...
CF 1530C - Pursuit
CF 1530C - Pursuit Rating: 1200 Tags: binary search, brute force, greedy, sortings Solve time: 45s Verified: no Solution Problem Understanding We have a contest with multiple stages, each stage giving between 0 and 100 points. You and Ilya have already completed n stages, and we know the scores for both of you. The contest ranks a contestant by taking only the highest k - floor(k / 4) scores out...
CF 1561C - Deep Down Below
CF 1561C - Deep Down Below Rating: 1300 Tags: binary search, greedy, sortings Solve time: 1m 39s Verified: yes Solution Problem Understanding We are given a hero facing a sequence of caves. Each cave contains a number of monsters, each with an armor value, and the hero can defeat a monster only if his current power is strictly greater than the monster's armor. After defeating a monster, the hero's power...
CF 1575A - Another Sorting Problem
CF 1575A - Another Sorting Problem Rating: 1100 Tags: data structures, sortings, strings Solve time: 12m 47s Verified: no Solution Problem Understanding We have a collection of distinct book titles, all with the same length. The books are not sorted using ordinary lexicographic order. When comparing two titles, we scan from left to right until we find the first position where they differ. If that position is odd-numbered, the smaller...
CF 1575L - Longest Array Deconstruction
CF 1575L - Longest Array Deconstruction Rating: 2100 Tags: data structures, divide and conquer, dp, sortings Solve time: 2m 34s Verified: no Solution Problem Understanding We start with an array. We may repeatedly delete arbitrary elements, and after each deletion the remaining elements close up together. For any resulting array, define its score as the number of positions where the value equals its current 1-based index. We want to choose...
CF 1648A - Weird Sum
CF 1648A - Weird Sum Rating: 1400 Tags: combinatorics, data structures, geometry, math, matrices, sortings Solve time: 1m 12s Verified: yes Solution Problem Understanding We are given a 2D grid of size $n \times m$ where each cell contains a color represented by an integer. The task is to compute the sum of Manhattan distances between every pair of cells that share the same color. The Manhattan distance between two...
CF 1654C - Alice and the Cake
CF 1654C - Alice and the Cake Rating: 1400 Tags: data structures, greedy, implementation, sortings Solve time: 1m 57s Verified: yes Solution Problem Understanding We are given the final weights of n cake pieces. These pieces were produced from a single initial cake by repeatedly choosing a piece of weight w and splitting it into two parts: floor(w / 2) ceil(w / 2) Exactly n - 1 such cuts were...
CF 1654A - Maximum Cake Tastiness
CF 1654A - Maximum Cake Tastiness Rating: 800 Tags: brute force, greedy, implementation, sortings Solve time: 1m 21s Verified: yes Solution Problem Understanding We are given a line of $n$ cakes, each with a weight $a_i$. The tastiness of the cake is defined as the sum of two adjacent pieces. We are allowed to reverse one contiguous subsegment of cakes at most once and then measure the tastiness. Our goal...
CF 1662I - Ice Cream Shop
CF 1662I - Ice Cream Shop Rating: - Tags: brute force, implementation, sortings Solve time: 5m 45s Verified: no Solution Problem Understanding We are asked to place a new ice cream shop along a beach where huts are positioned at regular intervals of 100 meters. Each hut contains a certain number of people who will buy ice cream only from the shop that is strictly closest to their hut. There...
CF 1662N - Drone Photo
CF 1662N - Drone Photo Rating: - Tags: combinatorics, math, sortings Solve time: 1m 27s Verified: yes Solution Problem Understanding We are asked to count the number of ways to select four contestants standing on the vertices of a rectangle in an $n \times n$ grid, such that when forming a banner using the two youngest contestants as one pole and the two oldest as another, the poles do not...
CF 1725B - Basketball Together
CF 1725B - Basketball Together Rating: 1000 Tags: binary search, greedy, sortings Solve time: 1m 59s Verified: yes Solution Problem Understanding We are asked to form teams from a list of candidate basketball players, each with an integer power. There is an opposing team with power $D$, and a team we form wins if the total power of its members exceeds $D$. The twist is that before each match, the...
CF 1776C - Library game
CF 1776C - Library game Rating: 2500 Tags: games, greedy, interactive, sortings Solve time: 1m 21s Verified: no Solution Problem Understanding We are playing a sequential game on a line of labeled sections, each section representing a distinct subject. Each day, one of two players chooses a contiguous interval of sections, constrained by a fixed length coming from a multiset of available “passes”. After the interval is announced, the opponent...
CF 1786B - Cake Assembly Line
CF 1786B - Cake Assembly Line Rating: 1300 Tags: brute force, sortings Solve time: 1m 39s Verified: yes Solution Problem Understanding We are given two ordered systems on a number line. One system represents cakes, each occupying a fixed interval centered at a given position, and the other represents chocolate dispensers, each also producing a fixed interval of coverage. All cake intervals are disjoint, and all chocolate intervals are disjoint....
CF 1877D - Effects of Anti Pimples
CF 1877D - Effects of Anti Pimples Rating: 1500 Tags: combinatorics, number theory, sortings Solve time: 1m 57s Verified: no Solution Problem Understanding We are given an array indexed from 1 to n. We repeatedly choose a non-empty subset of indices and mark them as special. Those chosen indices are colored black. After that, any still-unselected index becomes green if it is a multiple of at least one black index....
CF 1877B - Helmets in Night Light
CF 1877B - Helmets in Night Light Rating: 1000 Tags: binary search, greedy, sortings Solve time: 1m 46s Verified: no Solution Problem Understanding We are tasked with spreading an announcement to all residents of a village in the cheapest way possible. There are two ways to inform residents: Pak Chanek can directly tell someone at a fixed cost p , or a resident who already knows can inform others using...
CF 1866F - Freak Joker Process
CF 1866F - Freak Joker Process Rating: 3100 Tags: binary search, data structures, sortings Solve time: 1m 31s Verified: yes Solution Problem Understanding We are maintaining a group of players, each described by two evolving attributes: an offensive value and a defensive value. Over time, both attributes can change independently through updates. At any moment, we need to evaluate a ranking system that depends not only on the current values...
CF 1876C - Autosynthesis
CF 1876C - Autosynthesis Rating: 2100 Tags: constructive algorithms, dfs and similar, graphs, greedy, sortings Solve time: 3m 40s Verified: no Solution Problem Understanding We are given an array of positive integers a of length n . The task is to perform a sequence of "circle" operations on elements of a . Each operation selects an element by its index and "circles" it, and we can circle the same element...
CF 1876A - Helmets in Night Light
CF 1876A - Helmets in Night Light Rating: 1000 Tags: greedy, sortings Solve time: 3m 3s Verified: yes Solution Problem Understanding We are asked to distribute an announcement among $n$ residents at minimum cost. Pak Chanek can notify any resident directly at cost $p$, and each resident who receives the announcement can forward it to a limited number of other residents $a_i$, paying $b_i$ per share. The task is to...
CF 1876B - Effects of Anti Pimples
CF 1876B - Effects of Anti Pimples Rating: 1500 Tags: combinatorics, number theory, sortings Solve time: 1m 44s Verified: yes Solution Problem Understanding We are given an array of integers representing values at different positions. Chaneka can select one or more indices to color black. After that, every element at a position that is a multiple of a black index turns green. The score of a particular selection is the...
CF 1906F - Maximize The Value
CF 1906F - Maximize The Value Rating: 2100 Tags: data structures, sortings Solve time: 1m 45s Verified: yes Solution Problem Understanding We are given an array of size $N$, initially filled with zeros. There are $M$ operations; each operation is described by three integers $L_i, R_i, X_i$, meaning that if we execute this operation, we add $X_i$ to every element in positions $L_i$ through $R_i$. The queries are a bit...
CF 1912A - Accumulator Apex
CF 1912A - Accumulator Apex Rating: 1900 Tags: data structures, implementation, sortings Solve time: 1m 41s Verified: yes Solution Problem Understanding In this problem, Allyn starts with an integer accumulator, x , and is given k sequences of integers. On each turn, Allyn can take the first (leftmost) number from any non-empty sequence and add it to x , but only if the resulting value of x stays non-negative. The...
CF 1940D - Almost Certainly
CF 1940D - Almost Certainly Rating: - Tags: *special, constructive algorithms, data structures, sortings Solve time: 49s Verified: yes Solution Problem Understanding We are given several independent test cases. In each test case, there is a collection of elements that behave like values placed on a line or in a multiset, and we are allowed to perform a specific kind of operation that changes how these values are grouped or...
CF 1940B - Three Arrays
CF 1940B - Three Arrays Rating: - Tags: *special, constructive algorithms, implementation, sortings Solve time: 1m 23s Verified: yes Solution Problem Understanding We are given three arrays of integers. The task is to find the number of triplets (i, j, k) such that the first array's element a[i] is less than or equal to the second array's element b[j] , and the second array's element b[j] is less than or...
CF 1940C - Burenka and Pether
CF 1940C - Burenka and Pether Rating: - Tags: *special, data structures, dfs and similar, divide and conquer, dsu, graphs, sortings, trees Solve time: 1m 11s Verified: yes Solution Problem Understanding We are given a directed structure over positions 1 to n, where each position carries a value. The key restriction is that movement from one position to another is not arbitrary: you are only allowed to move forward in...
CF 1970A1 - Balanced Shuffle (Easy)
CF 1970A1 - Balanced Shuffle (Easy) Rating: 1000 Tags: implementation, sortings Solve time: 2m 8s Verified: yes Solution Problem Understanding We are given a string composed solely of opening and closing parentheses. The string is guaranteed to be a balanced parentheses sequence, which means the total number of "(" matches the number of ")" and every prefix of the string has at least as many "(" as ")". Our goal...