Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

You can use several words in query to find by all of them at the same time. In addition, if you are lucky search understands word forms and some synonyms. It supports search by title and author. Examples:

  • 305 — search for 305, most probably it will find blogs about the Round 305
  • andrew stankevich contests — search for words "andrew", "stankevich" and "contests" at the same time
  • user:mikemirzayanov title:testlib — search containing "testlib" in title by MikeMirzayanov
  • "vk cup" — use quotes to find phrase as is
  • title:educational — search in title

Results

1.
By rembocoder, 5 years ago, In English
Two Kinds of Dynamic Programming: Process Simulation Hello! I received a great response from the Codeforces community, so now I am starting a series of educational posts. Today I want to tell about a very useful classification of dynamic programming problems that I came up with through the years of practice. I don't claim the authorship of this idea, but still I've never seen it expressed explicitly, so I will introduce my own terms. Let's call it _"Subtask DP"_ (or _"Regular DP"_) and _"Process-Simulation DP"_. Today I will focus on the latter. ### The Regular approach How were you introduced to DP? In which terms? When I was at school, I was explained that DP is just splitting a task into subtasks. First, you introduce parameters to your problem. A set of values for each parameter is called a _state_ of the DP, which corresponds to a single subtask. Then you just need to find the answer for every state / subtask, and knowing the answer for the smaller subtasks shall help you with your current one. Let's look at an example: ...
Two Kinds of Dynamic Programming: Process Simulation, _"Regular DP"_) and _"Process-Simulation DP"_. Today I will focus on the latter., _process_ that builds such an object. Every path of this process (i.e. the sequence of steps) shall, it _"Subtask DP"_ (or _"Regular DP"_) and _"Process-Simulation DP"_. Today I will focus on the, l = 0; l <= k; l++) { // fix one of the correct final states of the process, much more suitable and meaningful for process simulation, just as the backward-style approach is for, of the process that lead into such state** _(where by state I also mean a set of values for each, starting state of our process. Let's denote by `dp[i][j][t][k]` the state, where there are `i` 0s, states of the process // (the last programmer is at the desk, all lines are written, with such a process: _"In the beginning programmer 1 is sitting at the desk. At each step either, ### The Process Simulation approach, And here is the main trick: **every transition in a DP graph is a step of the process at some state, Let's come up with some other process. Maybe instead of going through programmers, try going, Let's define a process that builds such an object (a valid distribution of `m` lines of code among, Problems involving sequences are the obvious candidates for process simulation. In such problems, So we have to know such parameters of the process:, The number of the states for such a process will be around `n * m * b`. But from every state there

Full text and comments »

  • Vote: I like it
  • +111
  • Vote: I do not like it

2.
By 055D, 6 years ago, In English
Codeforces Round #821 (Div. 2) Editorial Problem A is developed by [user:mejiamejia,2022-09-19]. #### [problem:1733A] <spoiler summary="Hints"> <spoiler summary="Hint 1"> $i$-th element moves only to $(i + xk)$-th position ($x$ is integer). </spoiler> <spoiler summary="Hint 2"> We cannot select $a_i$ and $a_{i + xk}$ simultaneously. In other words, if we can swap $a_i$ and $a_j$, we cannot select $a_i$ and $a_j$ simultaneously. </spoiler> <spoiler summary="Hint 3"> Among all elements $a_{i + xk}$ for each $i$ ($1 \le i \le k$), only one element is selected. </spoiler> </spoiler> <spoiler summary="Solution"> For each index $i$ ($k + 1 \le i \le n$), there is exactly one element among $a_1$ to $a_k$, which can swap with $a_i$. If $a_i$ is greater than that element, swap them. This process perform the operation at most $n - k$ times. After performing operations, select $a_1$ to $a_k$. This is the maximum score we can get. </spoiler> <spoiler summary="Solution Code"> [#172743256](https://codeforce...
$, which can swap with $a_i$. If $a_i$ is greater than that element, swap them. Thisprocess perform the, Simulation with $x$ slime balls processes as follows:

Full text and comments »

  • Vote: I like it
  • +152
  • Vote: I do not like it

3.
By rembocoder, history, 5 years ago, translation, In English
Dynamic Programming: Prologue Hello. This is a prologue to my previous posts, in which I'm going to briefly introduce a reader into the terminology of dynamic programming. This is not an exhaustive guide, but merely a preamble, so that an unprepared reader can get a full picture the same way I see it. ### Basic Terms **Dynamic programming** – the way to solve a problem by parametrizing it in such a way that an answer for some values of the parameters would help us find the answer for the other values of the parameters; and then finding the answer for all possible parameters' values. **DP state** – a specific set of values for each parameter (a specific _subtask_). **DP value** – the answer for a specific state (subtask). **Transition from state A to state B** – a mark meaning that in order to know the value for the state B, we need to know the answer for the state A. **Implementing a transition from A to B** – some action done when the answer for the state A is already known, satisfying the condit...
(`dp[i][j] = 0`). _This solution uses the Process Simulation approach, read my [post](https, [Two Kinds of Dynamic Programming: Process Simulation ](https://codeforces.me/blog/entry/100918), _This solution uses the Process Simulation approach, read my [post](https://codeforces.me/blog

Full text and comments »

  • Vote: I like it
  • +67
  • Vote: I do not like it

4.
By Mindeveloped, history, 8 months ago, In English
Codeforces Round 1086 (Div. 2) Editorial We hope that you have enjoyed our problems! [problem: 2208A] Idea by [user:Mindeveloped,2026-03-15], prepared by [user:Mindeveloped,2026-03-15] <spoiler summary="Hint 1"> It is always possible to rearrange the candies, unless candies of one specific color appears too often. </spoiler> <spoiler summary="Solution"> Let $x$ be the color with the highest number of candies. In case of ties, $x$ could be any of the candidates. Denote the number of candies with color $x$ as $a$. Conclusion: The answer to the problem is `YES` if and only if there are no more than $n^2 - n$ candies of color $x$; &mdash; in other words, $a\le n^2 - n$ holds. Proof of necessity: If there are more than $n^2 - n$ candies of color $x$, then there are less than $n$ candies not of color $x$. Since there are $n$ rows, at least one row will have no candies not of color $x$; therefore, such a row will be filled with candies of color $x$, violating the restrictions. Proof of sufficiency: If there a...
If $X_i$ is not found in $S$ during the simulation, it, edge from $ u $. - Repeat this process until $ R_u $ becomes empty. At that point, all outgoing

Full text and comments »

  • Vote: I like it
  • +100
  • Vote: I do not like it

5.
By rembocoder, history, 5 years ago, In English
How to solve DP problems: Regular Approach Hello! In the previous post I've introduced two kinds of dynamic programming: _Regular_ and _Process Simulation_. In it I've told how to solve DP problems using Process Simulation, please read it if you missed in order to understand the difference. Now I want to talk about tricks that help me solve DP problems with Regular approach. While with the Process Simulation approach we had to invent some process that would build us the desired objects, **in the Regular approach we're going to deal with the objects directly**. Each state of the DP _(i.e., a set of values for each parameter)_ will correspond to some class of the desired objects, and the corresponding value in the DP table will contain some information about that class, _which is in fact equivalent to the Subtask formulation I've introduced in the previous post_. In this post I'll focus on how to come up with transitions for the Regular DP, if you are already decided on the parameters. The general plan is: 1. Determine, ...
_Process Simulation_. In it I've told how to solve DP problems using Process Simulation, please read it if, Again, if you really want, it is possible to solve this problem using Process Simulation, but I, While with the Process Simulation approach we had to invent some process that would build us the

Full text and comments »

  • Vote: I like it
  • +80
  • Vote: I do not like it

6.
By Nickolas, 9 years ago, translation, In English
Codeforces Round #455 (Div. 2) Editorial #### [problem:909A] The most straightforward solution is to generate all possible logins (by trying all non-empty prefixes of first and last names and combining them) and find the alphabetically earliest of them. To get a faster solution, several observations are required. First, in the alphabetically earliest login the prefix of the last name is always one letter long; whatever login is generated using two or more letter of the last name, can be shortened further by removing extra letter to get an alphabetically earlier login. Second, the prefix of the first name should not contain any letter greater than or equal to the first letter of the last name, other than the first letter. Thus, a better solution is: iterate over letter of the first name, starting with the second one. [cut] Once a letter which is greater than or equal to the first letter of the last name is found, stop, and return all letter until this one plus the first letter of the last name. If such a letter ...
We can simulate the process described in the problem step by step, but this is too slow — a, ]}$. The complexity of this solution is $O(N^2)$. #### [problem:909D] We can simulate theprocess

Full text and comments »

  • Vote: I like it
  • +125
  • Vote: I do not like it

7.
By dario2994, 6 years ago, In English
About Problemsetting (for AtCoder and Codeforces) Since the amount of information available about the preparation of a competitive programming contest for AtCoder/Codeforces is very little, I decided to collect here what was my experience. I will try to both describe my experiences and give some general advice to wannabe problemsetters. I hope that this will be useful to future problemsetters who are "out of the loop". Moreover, participants might be curious to know what happens behind the scenes (and maybe the platforms may consider this as a form of constructive feedback). *Acronyms*: - AGC = Atcoder Grand Contest - GR = Codeforces Global Round ### Why I know something about problemsetting? I am in the competitive programming world since ~8 years: I have participated in IOI/ICPC/GCJ and a number of contests on AtCoder/Codeforces (and lately Codechef). I am not a top participant but, being in this world for so long, I know, more or less, all the standard tricks. Recently, I was the author of the *flagship conte...
be the author of a Global Round and asking some clarifications on the process. - 3 July: He

Full text and comments »

  • Vote: I like it
  • +936
  • Vote: I do not like it

8.
By darkkcyan, 5 years ago, In English
Codeforces Round #763 (Div. 2) Editorial In my opinion, all of the problems have a very simple solution and actually require no special data structure at all. To demonstrate the point, I will also use EvErYoNe'S fAvOrItE lAnGuAgE: **Pascal**. I will also include some notes, which are not related to the solution at all, but I find them interesting, so I will also include them in. ## [A. Robot Cleaner](https://codeforces.me/contest/1623/problem/A) Obviously, the problem is solvable using simulation. But it is solvable in $O(1)$ time as well, and I will discuss it. <spoiler summary="Tutorial">[tutorial:1623A]</spoiler> <spoiler summary="Problem note"> - Yes, I purposely make the constraint small. Firstly, the simulation solution is straightforward to think of, and I think everyone should be able to do it. But secondly, I wanted to see high-rated people suffering from going too fast :). - I hope that you like the animation! If you didn't know it yet, I use the library called [Manim](https://www.manim.community/), ...
/1623/problem/A) Obviously, the problem is solvable using simulation. But it is solvable in $O(1, simulation solution is straightforward to think of, and I think everyone should be able to do it. But

Full text and comments »

  • Vote: I like it
  • +221
  • Vote: I do not like it

9.
By Nerevar, 14 years ago, translation, In English
Codeforces Round #154 (Div. 2) — tutorial Sorry for the short tutorial: we are too busy preparing and conducting school competition. [problem:253A] Lets assume that we have more boys than girls (the other case is solved similarly). Then we can construct one of the optimal solutions in the following way: we add pairs consisting of a boy and a girl (BG, in that order) to the end of the line until we don't have girls any more. Then add remaining boys to the end of the line. For instance, with 7 boys and 4 girls we will come to the solution BGBGBGBGBBB. [problem:253B] For each $x$ from 1 to 5000 calculate $count(x)$ &mdash; the number of measurements equal to $x$. The iterate over all possible minimal values $m$ (from 1 to 5000). For a fixed $m$ we can easily figure out which numbers we have to erase: we should erase every number $k$ that $k < m$ or $k > 2 \cdot m$. To find out the number of such values in the given sequence, we should sum up values $count(k)$ for all such $k$. [problem:253C] One of the solutions...
partial sums. [problem:253E] First lets learn how to simulate the process with all priorities, First lets learn how to simulate the process with all priorities known. We will keep the priority

Full text and comments »

  • Vote: I like it
  • +40
  • Vote: I do not like it

10.
By nika-skybytska, 6 years ago, In English
Round #696 (Div. 2) video solutions and my perspective [A-D] [solutions on github](https://github.com/Sky-Nik/Codeforces/tree/main/696-2), [video on YouTube](https://youtu.be/V-5gSFGaCho). Short text solutions: ### A. Puzzle From the Future Greedy: first optimize the length (no consecutive equal numbers), then the individual digits starting from the most significant ones. $O(t \cdot n)$ overall. ### B. Different Divisors The least prime divisor $p$ should be at least $d + 1$. Then the second prime divisor should be at least $p + 1$. Selecting the least prime number bigger than something is a binary search in the array of primes. The array of primes can be generated with a sieve. $O(\max d \log \log \max d + t)$ overall. ### C. Array Destruction Each operation should involve max because it can't be removed later. If we know the initial $x$ then the simulation of this process takes $O(n \log n)$ with `std::multiset` or $O(n)$ with some smart solution from neal. Because the initial value of $x$ also includes $\max_i a_i$, it remai...
initial $x$ then the simulation of this process takes $O(n \log n)$ with `std::multiset` or $O(n)$ with, $ then the simulation of this process takes $O(n \log n)$ with `std::multiset` or $O(n)$ with some smart

Full text and comments »

  • Vote: I like it
  • +18
  • Vote: I do not like it

11.
By AdityaDSingh, history, 16 months ago, In English
De Shaw Online Assessment (OA) IIT Bhubaneswar (2025) (for SDE Intern) This is a write-up of the DE Shaw Online Assessment for the SDE Intern 2025 role. The test consisted of 3 DSA problems with the following structure: Format ------ 3 programming questions Separate timers for each question: Q1: 20 minutes Q2: 30 minutes Q3: 30 minutes - Questions had to be attempted in order. - No ability to return to a previous question. - Time left on a previous question could not be transferred to the next. ### Problem 1: Divisible Substrings (20 mins) Given a string s of lowercase English letters (length ≤ 1000), map each character c to a value using: ~~~~~ val(c) = (c - 'a' + 1) / 3 + 1 ~~~~~ For example: 'a', 'b' → 1 'c', 'd', 'e' → 2 ... 'x', 'y', 'z' → 9 Count the number of substrings such that the sum of character values in the substring is divisible by the length of that substring. A brute-force O(n²) approach, utilizing a nested loop, is effective. ### Problem 2: Airport Scanner Simulation (30 mins) Given two a...
, utilizing a nested loop, is effective. ### Problem 2: Airport Scanner Simulation (30 mins) Given two, This is a simulation problem. Maintain two queues (one for arrivals, one for departures), both with

Full text and comments »

  • Vote: I like it
  • +14
  • Vote: I do not like it

12.
By MrMoon, 4 months ago, In English
PSUT JCPC Qualification 2026 Tutorial Hints are mostly related, so you have to think and get some observations before understanding the next, make sure to understand the code before you submit it as well, "Most problems in life are due two reasons: act without thinking, think without acting" ~the,2026-08-02 poet,2026-08-01 Big thank you to the testers for improving this problem set beyond what it was, [user:the_seal,2026-08-02] , [user:Rayo,2026-08-02], [user:samsoom,2026-08-02], [user:lazlooz,2026-08-02] The contest exist in the group so make sure to join https://codeforces.me/group/ppRciMeJFg Some of these problems were inspired from other problems across the internet, "If I have seen further, it is by standing on the shoulders of giants." ~the,2026-08-02 poet [Problem A: MrMoon creates Lucky Number Seven Command](https://codeforces.me/group/ppRciMeJFg/contest/707652/problem/A) ================== ### 7 [Problem B: Moon creates seal backflips](https://codeforces.me/group/ppRciMeJFg/contest/707652/probl...
A literal simulation (using a queue data structure and simulating turn, way down to Team $n$. We must process every single match chronologically (arranging events in the

Full text and comments »

  • Vote: I like it
  • +21
  • Vote: I do not like it

13.
By SummerSky, 9 years ago, In English
Notes on Codeforces Beta Round #74, A, B, C, D, E(Orthogonal List) [problem:90A] There are at most 300 students, and thus we can directly simulate the whole process, i.e., what happens in each minute. The simulation terminates when no students are left. [problem:90B] The implementation is straightforward. We can enumerate each letter, and only those that appear exactly once in the corresponding row and column should be output. [problem:90C] An interesting problem. Suppose that $\Delta x$ elements are taken away. To guarantee that the $n-1$ sums keep the same, the changing quantity for each element must be $-\Delta x, \Delta x, -\Delta x, \Delta x,...$. Therefore, if $n$ is an even number, it is impossible to take away any elements, since the total sum can not be changed. For an odd number $n$, it can be seen that to take away $\Delta x$ elements, we have to carry out $\Delta x + \frac{n-1}{2}\times \Delta x=\frac{n+1}{2}\times \Delta x$ moves. For each minute, at most $m$ moves can be conducted, and thus $\Delta x \le \frac{2m}{n+1}...
There are at most 300 students, and thus we can directly simulate the whole process, i.e., what, process, i.e., what happens in each minute. The simulation terminates when no students are left

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

14.
By goryinyich, 15 years ago, In English
Codeforces Beta Round #74 - Short editorial except Div. 1 E <p>Very strange contest. On the one hand - interesting problems, on the other hand - very disbalanced difficulty. To my mind, problem scoring should be the following:</p><div>Div. 1: 1000-1500-1500-1000-???</div><div>Div. 2: 500-500-1500-2000-2000</div><div><br></div><div>That's why I don't very like this contest. But, once again, problems were interesting, thanks to the author!</div><div><br></div><div>Now short editorial.</div><div><br></div><div>Problem A - Cableway (div. 2)</div><div>The only thing in this problem is to write expression for time of the arrival for final group of students of each color. This could be done with the following code:</div><div><div>ans = 30 + 3*((r+1)/2-1);</div><div>if (g) ans = max (ans, 31 + 3*((g+1)/2-1));</div><div>if (b) ans = max (ans, 32 + 3*((b+1)/2-1));</div></div><div><br></div><div>Problem B - African crossword (div. 2)</div><div>Due to the small restrictions, the problem could be solved with the straightforward O(n*m*(n+m)) algo of finding ...
From test 1 it becomes clear that the game process is dependent on history, so any DP schemes

Full text and comments »

  • Vote: I like it
  • +19
  • Vote: I do not like it

15.
By romanandreev, 11 years ago, translation, In English
Codeforces Round #342 (Div. 2) : editorial [problem:625A] ------------------ Idea author: collaboration, preparation: [user:feldsherov,2016-02-07]. If we have at least $b$ money then cost of one glass bottle is $b - c$. This means that if $a \leq b - c$ then we don't need to buy glass bottles, only plastic ones, and the answer will be $\left\lfloor\frac{n}{a}\right\rfloor$. Otherwise we need to buy glass bottles while we can. So, if we have at least $b$ money, then we will buy $\left\lfloor\frac{n - c}{b - c}\right\rfloor$ glass bottles and then spend rest of the money on plastic ones. This is simple $O(1)$ solution. [problem:625B] ------------------ Idea author: [user:gustokashin,2016-02-07], preparation: [user:thefacetakt,2016-02-07]. Lets find leftmost occurrence of the second word in the first one. We need to add # to remove this occurrence, so where we would like to put it? Instead of the last symbol of this occurrence to remove as many others as we can. After that we will continue this operation after the n...
: [user:iskhakovt,2016-02-07]. We want to efficiently simulate the process from the problem, We want to efficiently simulate the process from the problem statement. Lets have a data structure

Full text and comments »

  • Vote: I like it
  • +76
  • Vote: I do not like it

16.
By Nourhan_Abo-Heba, history, 15 months ago, In English
STL Basics – lower_bound, upper_bound, BST, Set, Multiset, Map, Priority Queue # Advanced STL Structures — A Complete Guide Hi everyone! In this lecture we'll go deeper into STL structures that are **must-know** for competitive programming. --- ## 1. Iterators & Vectors Iterators are like pointers that let you navigate through containers. ```cpp vector<int> v = {1, 2, 3, 4, 5}; auto it = v.begin(); // points to first element auto end = v.end(); // points AFTER last element sort(v.begin(), v.end()); // sort entire vector v.end() - v.begin(); // size of vector ``` ### Key Facts * `v.begin()` → iterator to first element * `v.end()` → iterator AFTER last element (not the last element itself!) * `v.size()` = `v.end() - v.begin()` ### Important Trick Count numbers in range `[l, r]` = `r - l + 1`. This formula appears constantly in: - Binary search problems - Range queries - Coordinate compression **Example:** ```cpp // How many integers from 5 to 10 inclusive? int count = 10 - 5 + 1;...
of distances * **Greedy problems** → always process smallest/largest element * **Eventsimulation, /largest element * **Event simulation** → process events in time order

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it

17.
By rqi, history, 3 months ago, In English
LLMs Cheating in Training Some people use LLMs to cheat on Codeforces. It turns out that LLMs also cheat during the reinforcement learning training process; this is called "reward hacking". As LLMs have gotten stronger, their own cheating during training has gotten worse. Here are some examples of advanced reward hacks: 1. Reconstructing a test by simulating the pseudorandom number generator process. Perhaps some of us have done similar things. ![ ](https://raw.githubusercontent.com/rqi3/cf-blog-assets/main/fig4.png) 2. Replacing the Python library. This doesn't work on Codeforces! ![ ](https://raw.githubusercontent.com/rqi3/cf-blog-assets/main/fig3.png) 3. Spawning a background process. ![ ](https://raw.githubusercontent.com/rqi3/cf-blog-assets/main/fig5.png) These were done as part of a research run where we intentionally trained the model on many environments where reward hacking was possible, in order to study how such a model behaves after training. ![ ](https://raw.githubusercontent....
reinforcement learning training process; this is called "reward hacking". As LLMs have gotten stronger

Full text and comments »

  • Vote: I like it
  • +216
  • Vote: I do not like it

18.
By halyavin, 11 years ago, In English
Educational Codeforces Round 10 Challenge Overview. 652A &mdash; Gabriel and Caterpillar ------------------------------ I have lost count of number of different challenges in this problem. Only 14 author tests for such a tricky problem were clearly not enough. There were 2 types of challenges. The first type use integer overflow. When I saw that both <i>h</i><sub>1</sub>, <i>h</i><sub>2</sub> and <i>a</i>, <i>b</i> are bounded by 10<sup>5</sup> I suspected that overflow could be a problem. But my solution divided heights by speeds to get the number of days. Surely there are no need to multiply these quantities I thought. Boy I was wrong. A lot of solutions used a simulation of the process. As long as <i>a</i> &gt; <i>b</i> and the caterpillar is going up, there is no problem. But if the caterpillar is going down, you need to give up eventually and return -1. The largest positive answer is about 10<sup>5</sup>/12 but the largest lose of height per day is about 12&middot;10<sup>5</sup>. The product is about 10<sup>10</sup> &gt; 2<...
multiply these quantities I thought. Boy I was wrong. A lot of solutions used a simulation of the, wrong. A lot of solutions used a simulation of the process. As long as a > b and the

Full text and comments »

  • Vote: I like it
  • +58
  • Vote: I do not like it

19.
By ayanasamuel, 8 months ago, In English
FOCUS-ASTU-TECH-COMMUNITY-CONTEST-1 Editorial #[contest:679752] Hello everyone! Welcome to the editorial for our mashup contest. We selected a mix of classic implementation, greedy, and constructive problems. The goal was to test logical thinking without getting bogged down in heavy data structures. Below you will find hints, tutorials, and solutions for each problem. We used spoiler tags to keep things clean. Try to solve it yourself before clicking! Happy coding! ## Problem-A:[problem:679752A] **Tags:** `Math` `Brute Force` `Simulation`<br> **Difficulty:** ⭐ (Very Easy) This is a classic implementation problem that tests your ability to simulate a process step-by-step. <spoiler summary="Understanding the Problem"> #### The Goal We have **two bears**: - **Limak** weighs `a` - **Bob** weighs `b` We know: $$a \le b$$ Every year: - Limak's weight **triples**: \(a \times 3\) - Bob's weight **doubles**: \(b \times 2\) We need to find the **number of years** it takes for **L...
### Approach: Frequency Array + Simulation 1. **Data Structures, a **Brute Force Simulation** approach. This means we will simply simulate the process exactly as, the program running too slowly. We can use a **Brute Force Simulation** approach. This means we will

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

20.
By a2sv, history, 4 years ago, In English
A2SV Gen 4 - Camp Contest 2 Editorial [problem:430380A] <spoiler summary="Hint"> Try Binary Search. </spoiler> <spoiler summary="Solution"> Use binary search to find the position of the smallest name larger than the given name. </spoiler> <spoiler summary="Code 1"> ~~~~~ from sys import stdin n = int(stdin.readline().strip()) queue = list(stdin.readline().strip().split()) q = int(stdin.readline().strip()) for _ in range(q): left, right = 0, n &mdash; 1 val = stdin.readline().strip() best = len(queue) while left <= right: mid = (left + right) // 2 if queue[mid] < val: left = mid + 1 else: best = mid right = mid - 1 print(best) ~~~~~ </spoiler> <spoiler summary="Code 2"> ~~~~~ from sys import stdin import n = int(stdin.readline().strip()) queue = list(stdin.readline().strip().split()) q = int(stdin.readline().strip()) for _ in range(q): left, right = 0, n &mdash; 1 ...
We can notice that single-elimination bracket and merge sort have a similar process. We can

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

21.
By Jrke, history, 6 months ago, In English
IICPC DELTA 2026 # Applications for the IICPC DELTA Program are now open! Hello everyone! Registrations for the **IICPC DELTA Program 2026** are now officially open. Welcome to **DELTA — Discovery and Early Learning in Trading & Algorithms**, a highly selective initiative by IICPC focused on identifying and nurturing exceptional early undergraduate talent interested in quantitative trading, algorithms, technology, systems and problem solving. This edition is proudly supported by leading quantitative trading and technology firms including **Optiver**, **Hudson River Trading** and more. ## About DELTA DELTA is designed to give high-potential students early exposure to the world of quantitative trading and advanced technology through a rigorous combination of assessments, competitions, interviews, mentorship and industry interaction. ![ ](/predownloaded/d8/86/d886af3cd828e83d940e68775e22e83b4a68fcaf.png) Participants will go through challenging **Trading** and **Technology** tracks...
- Rigorous 3-Stage Selection Process - Designed for High Potential Early Talent ## Eligibility

Full text and comments »

  • Vote: I like it
  • +32
  • Vote: I do not like it

22.
By a2sv, history, 4 years ago, In English
A2SV Gen 4 — Camp Contest 2 Editorial [problem:430380A] <spoiler summary="Hint"> Try Binary Search. </spoiler> <spoiler summary="Solution"> Use binary search to find the position of the smallest name larger than the given name. </spoiler> <spoiler summary="Code 1"> ~~~~~ from sys import stdin n = int(stdin.readline().strip()) queue = list(stdin.readline().strip().split()) q = int(stdin.readline().strip()) for _ in range(q): left, right = 0, n - 1 val = stdin.readline().strip() best = len(queue) while left <= right: mid = (left + right) // 2 if queue[mid] < val: left = mid + 1 else: best = mid right = mid - 1 print(best) ~~~~~ </spoiler> <spoiler summary="Code 2"> ~~~~~ from sys import stdin import n = int(stdin.readline().strip()) queue = list(stdin.readline().strip().split()) q = int(stdin.readline().strip()) for _ in range(q): left, right = 0, n - 1 val = stdin...
can notice that single-elimination bracket and merge sort have a similar process. We can leverage, We can notice that single-elimination bracket and merge sort have a similar process. We can

Full text and comments »

  • Vote: I like it
  • -2
  • Vote: I do not like it

23.
By Karan_reddy.go, history, 4 months ago, In English
Flipkart Online Assessment (OA) – IIT Bhubaneswar (2026) ( Software Development Engineer ) This is a write-up of the **Flipkart Grid SDE Intern 2026 Online Assessment**. The assessment consisted of **3 coding questions** to be solved in **90 minutes**. ## Format * **3 Programming Questions** * **Total Duration:** 90 Minutes --- # Problem 1: Good Numbers You are given two integers: * **n** – number of digits in the number (**n ≤ 9**) * **k** – divisor (**k ≤ 100**) Find the **sum of all n-digit numbers** that are divisible by **k**. ## Example 1 **Input** ```text n = 2 k = 5 ``` **Valid Numbers** ```text 10, 15, 20, 25, ..., 95 ``` **Output** ```text 995 ``` --- ## Example 2 **Input** ```text n = 1 k = 3 ``` **Valid Numbers** ```text 3, 6, 9 ``` **Output** ```text 18 ``` --- ## Example 3 **Input** ```text n = 3 k = 100 ``` **Valid Numbers** ```text 100, 200, 300, ..., 900 ``` **Output** ```text 4500 ``` --- ## Approach The brute-force solution iterates ove...
from index **0**, process one level at a time and print the last element of that level, the array without constructing the tree. * **Q3** was a Medium simulation problem based on the 2048

Full text and comments »

  • Vote: I like it
  • -19
  • Vote: I do not like it

24.
By dhroovs, history, 10 months ago, In English
Some random things Codeforces slowly taught me I was planning to write something useful, but then I realized most of my Codeforces experience has been confusion, wrong answers, and small moments of understanding. So here are a few random things I learned that have nothing to do with algorithms directly. First, WA is normal. I used to feel bad every time my solution failed on some hidden test. Now it feels almost expected. If a solution gets accepted on the first try, it honestly feels suspicious. Most of the time, WA just means I missed something obvious, or something not obvious at all. Either way, it’s part of the process. Second, editorials can be painful to read. You spend a lot of time thinking, trying different ideas, maybe even writing a long solution. Then you open the editorial and see a simple observation that solves everything. At first it’s frustrating, but slowly you start appreciating how powerful simple thinking is. It also teaches you how much more there is to learn. Time behaves strangely during contests...
something obvious, or something not obvious at all. Either way, it’s part of theprocess. Second

Full text and comments »

  • Vote: I like it
  • +133
  • Vote: I do not like it

25.
By Geothermal, history, 7 years ago, In English
AtCoder Beginner Contest 158 English Solutions It's been a while since I've done one of these! --- #A &mdash; Station and Bus After parsing the problem statement, we see that we simply need to determine whether the two companies each operate at least one station, since if this is the case, those stations will be connected, and otherwise, if one company operates every station, no connections will be built. This is now a fairly easy task---one way to do it is to check whether every character in the string is the same, printing No if this is the case and Yes otherwise. Alternatively, we can directly compare $S$ to "AAA" and "BBB", rejecting if the input is one of these strings and accepting otherwise. There are a wide variety of approaches, but they're all essentially equivalent. Runtime: $O(1)$. [Click here for my submission.](https://atcoder.jp/contests/abc158/submissions/10587980) --- #B &mdash; Count Balls Given the large limits on $N, A,$ and $B$, a brute force simulation will be vastly too slow---we need...
Given the large limits on $N, A,$ and $B$, a brute force simulation will be vastly too slow---we

Full text and comments »

  • Vote: I like it
  • +81
  • Vote: I do not like it

26.
By someone_lunatic_lyk_hell, history, 2 years ago, In English
Help needed in problem involving constructive queue simulation **Hello Codeforces community,** I've been working on a problem involving queue dynamics and chair allocation, and **I'm seeking your expertise to find an efficient solution that fits within tight constraints.** Problem Statement: Description: **You are given a queue of n people, numbered from 1 to n. Each person i has an initial preferred chair number Pi, which is a positive integer.** There is an infinite number of chairs, labelled with positive integers starting from 1. The queue operates under the following rules: Queue Processing: `People are processed in the order they appear in the queue.` Chair Allocation Process: `When a person reaches the front of the queue, they attempt to sit on their current preferred chair Pi.` If the chair Pi is unoccupied: `They sit on chair Pi and leave the queue.` If the chair Pi is already occupied: `They are sent to the end of the queue and their preferred chair number increases by 1. They will attempt to sit on this new pre...
Help needed in problem involving constructive queue simulation, appear in the queue.` Chair Allocation Process: `When a person reaches the front of the queue, they, Chair Allocation Process: `When a person reaches the front of the queue, they attempt to sit on, This process continues until all people have been allocated a chair.

Full text and comments »

27.
By Lewin, history, 11 years ago, In English
Wunder Fund Round 2016 Editorials I hope you enjoyed the contest! Let me know if you find any errors below. Thanks for participating. Short solutions: - Slime Combining: You can just do what's described in the statement. Or, maybe you can do something with the binary representation of the number. - Guess the permutation: Find out where 1 should go. Then, find out where 2 should go, and so on. - Constellation: Start with a triangle and break it up. Or, choose a point and look at angles. Or, sort by x coordinate. - Hamiltonian Spanning Tree: Two cases: X > Y and X <= Y. For X > Y we can almost always avoid the spanning tree edges. For X <= Y we can do something greedy. - Robot Arm: Make a segment tree on segments. A segment is basically just a linear transformation, which can be described with three numbers. - Double Knapsack: Make the problem harder. Let's say I want a consecutive sublist of both lists that have equal sums. Then use pigeonhole principle to get an answer. - Combining Slimes: Use conditional e...
) ----------------------- We can simulate the process described in the problem statement. There are many possible

Full text and comments »

  • Vote: I like it
  • +128
  • Vote: I do not like it

28.
By Errichto, 10 years ago, In English
Good Bye 2016 — hints and codes You can download my codes to all problems [here](http://www.filedropper.com/codes_1). I will write a full editorial in the next few days. Now you can read hints and short solutions. [problem:750B] <spoiler summary="hint"> Create a variable that will denote your current distance from the North Pole. What are allowed values of this variable? When can't we go West or East? </spoiler> [problem:750C] <spoiler summary="hint1"> Let $x$ denote the initial rating (or his final rating, whatever is easier for you to think about). The information that Limak is in some division in the $i$-th contest gives us some inequality for $x$. Can you see it? </spoiler> <spoiler summary="hint2"> For every contest we know that the current rating is $x$ increased by some prefix sum of c_i (changes of rating). If Limak is in the division 1, we have inequality x+prefSum >= 1900 so we have x >= 1900-prefSum. If Limak is in the division 2, we have inequality x_prefSum <= 1899 so it is ...
summary="hint1"> The intended solution is also able to process queries of form "change the i-th

Full text and comments »

Tutorial of Good Bye 2016
  • Vote: I like it
  • +168
  • Vote: I do not like it

29.
By dreamoon_love_AA, 12 years ago, In English
Codeforces Round #292 Editorial Thanks to [user:johnathan79717,2015-03-10] fo polish my words. #### [515-A Drazil and Date](http://codeforces.me/problemset/problem/515/A) If Drazil chooses the shortest path from (0,0) to (a,b), it takes $|a| + |b|$ steps. So we know that all numbers less than $|a| + |b|$ are impossible to be the number of steps that Drazil took. Now consider when the number of steps is not less than $|a| + |b|$. When Drazil arrives at $(a,b)$, he can take two more steps such as $(a,b)$ -> $(a,b+1)$ -> $(a,b)$ to remain at the same position. So we know that for all $s$ such that $s \geq |a| + |b|$ and $(s - (|a| + |b|)) \% 2 = 0$, there exists a way for Drazil to get to $(a,b)$ in exactly $s$ steps. The last part we should prove is that it's impossible for Drazil to arrive at (a,b) in exactly $s$ steps when $(s - (|a| + |b|)) \% 2 = 1$. We can color all positions $(x,y)$ where $(x+y) \% 2 = 0$ as white and color other points as black. After each step, the color of the p...
$n*m$ days, there won't be any changes anymore since then. We can simulate the process of having

Full text and comments »

  • Vote: I like it
  • +132
  • Vote: I do not like it

30.
By mohammedehab2002, 8 years ago, In English
Codeforces round #525 editorial [problem:1088A] --------------- Well, the constraints allow a brute-force solution, but here's an $O(1)$ solution: If $x=1$, there's no solution. Otherwise, just print $x-x\%2$ and 2. Code link: https://pastebin.com/LXvuX8Ez Time complexity: $O(1)$. [problem:1088B] --------------- Let $s$ be the set of numbers in input (sorted and distinct). In the $i^{th}$ step, $s_i$ is subtracted from all bigger or equal elements, and all smaller elements are 0. Thus, the answer in the $i^{th}$ step is $s_i-s_{i-1}$ ($s_0=0$). Code link: https://pastebin.com/bpz1YxBe Time complexity: $O(nlog(n))$. [problem:1088C] --------------- The editorial uses 0-indexing. Both solutions make $a_i=i$. #### First solution, n adds and 1 mod First, let's make $a_i=x*n+i$ (for some $x$). Then, let's mod the whole array with $n$ (making $a_i=i$). If the "add update" changed one index, we can just add $i+n-a_i\%n$ to index $i$. The problem is, if we make $a_i=x*n+i$, then updat...
recommend the simulation. Let's build $a$ and $b$ bit by bit from the most significant to the least

Full text and comments »

  • Vote: I like it
  • +116
  • Vote: I do not like it

31.
By -Morass-, history, 9 years ago, In English
Problem Topics Good Day to you! I've been asked to make some topic-wise list of problems I've solved. Even though I couldn't involve all problems, I've tried to involve at least "few" problems at each topic I thought up (I'm sorry if I forgot about something "easy"). I've alredy made such list once anyway I've tried to include more problems now &mdash; so here it is: <spoiler summary="aho"> http://www.spoj.com/problems/ADAJOBS/ URI 2226 (5) //[NICE][NUMBERS][DP] http://www.spoj.com/problems/SUB_PROB/en/ http://codeforces.me/contest/696/problem/D 8 http://www.spoj.com/problems/AHOCUR/ 5 //Aho-Corassic + DP https://www.codechef.com/problems/LYRC (5) //Sample aho-brute-force http://codeforces.me/problemset/problem/346/B //Proposed by [user:bradyawn,2019-08-03] </spoiler> <spoiler summary="automat"> 6861 [LA] //CYK UVA 10679 //Suffix Automat http://www.spoj.com/problems/STRMATCH/ //Suffix Automat &mdash; trie might do too http://www.spoj.com/problems/NSUBST...
(4) //[MATH][MODULO][SIMULATION] http://codeforces.me/contest/68/problem/C (5) //[VERY NICE

Full text and comments »

  • Vote: I like it
  • +428
  • Vote: I do not like it

32.
By havaliza, 14 years ago, In English
Codeforces Round #168 Editorial Hi :) Here's the editorial for round #168. This time I tried to do my best to prepare a good contest. In some parts I failed but I still learned many things which will surely help me to do better next times! ^.^ I hope you've liked the problems. :) ## [problem:275A] Author: [user:havaliza,2013-02-22] For each light you should count the number of times it’s been toggled. Consider a light is toggled $k$ times. If $k$ is even then the final state of the light is ‘on’ otherwise it’s ‘off’. The implementation would be easy. You may look at the accepted solutions as reference. ## [problem:275B] Author: [user:havaliza,2013-02-22] Consider a pair of black cells. There exist at most two different valid paths we can take between these two cells. The naïve solution would be to check the existence of at least one of these paths for each pair of black cells. There are $O(n^{2} m^{2}) $ such pairs and each pair can be checked in $O(n+m)$. So the time complexity will be $O(n^{2} ...
large and the beam might travel a long path before entering a loop. So naïve simulation will surely

Full text and comments »

  • Vote: I like it
  • +72
  • Vote: I do not like it

33.
By Endagorion, history, 10 years ago, In English
Yandex.Algorithm 2016, third elimination round editorial I hope you've enjoyed the problems! Please ask your questions and report flaws in the comments. ### Problem A First insight is that two spells are always enough. Why? Let's freeze all leftbound penguins at point $10^{-9}$ and all rightbound penguins at point $10^9$. So the only problem is to determine when only one spell is enough. If that holds, there should exist a point which all penguins will cross at some moment. Let's put this point at $x_+$~--- rightmost point among penguins' coordinates which run to the right. Now all rightbound penguins will cross this point. If there is a leftbound penguin which doesn't cross $x_+$ then its coordinate $x_-$ must be less than $x_+$. But in this case there are two penguins running away from each other~--- clearly one spell will not suffice. So, the easiest and most effective solution is to find $x_+$~--- the location of rightmost rightbound penguin, and $x_-$~--- the location of leftmost leftbound penguin, and check if $x_- < x_+$. ...
whole process is looped and the answer is $-1$. On the other hand, if $M > A$ (the largest possible

Full text and comments »

  • Vote: I like it
  • +41
  • Vote: I do not like it

34.
By vlalit834, history, 6 months ago, In English
AtCoder AI Tagged Problems: Instant Topic-Based Problems # AtCoder AI Tagged Problems: Instant Topic-Based Problem Discovery *A zero-configuration platform for filtering AtCoder problems by algorithmic topic, difficulty, and contest type.* --- [AtCoder AI Tagged Problems](https://atcoder-ai-tagged-problem.vercel.app/) provides structured access to the AtCoder problem set through AI-generated topic annotations and a multi-dimensional filtering interface. The application requires no installation, no user account, and no browser extensions. --- ## Core Capabilities - **AI-Generated Topic Annotations**: Every problem in the AtCoder archive is annotated with algorithmic topics including Dynamic Programming, Graph Theory, Greedy Algorithms, Mathematics, String Processing, and Computational Geometry. Tags are generated automatically and available immediately for all problems, without dependence on community voting or manual curation. - **Multi-Criteria Filtering Interface**: Problems can be filtered concurrently by algorithmic ...
Contest View (problems organized by contest with visual difficulty indicators forsimulation-style

Full text and comments »

  • Vote: I like it
  • -1
  • Vote: I do not like it

35.
By bhikkhu, history, 4 years ago, In English
Introduction to Reinforcement Learning. We would like to create a model that which when given a game state, it predicts the best move. Lets say our game is the simple Tic Tac Toe. It is a small game and we can train the AI for it in a handful of minutes. ![ ](/predownloaded/d2/4e/d24ea5e6a7df4ec314d9351551d1d26e9cbab09a.jpg) Here is our example neural network, reduced the number of hidden layer to avoid cluttering. ![ ](/predownloaded/ef/90/ef90adea0d76a110d429fd1d177ebcb2746f7662.png) In the above network, the inputs are going to be board states. For example, ![ ](/predownloaded/fd/88/fd882161d7637bbcd210efa0a6a734a647aca72e.png) **Lets assume the neural networks always predicts from the perspective of that the turn is of player -1**. If we can build a neural network, we can just flip the board and predict for the opposite player, easy peasy. I use the algorithm mentioned at OPEN AI blog for training. Its almost same for the CartPole Reinforcement Learning environment from OpenAI GYM https://spinn...
algorithm looks like this: 1. Run a number of simulations / battles / episodes For everysimulation

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it

36.
By greateric, history, 4 months ago, In English
Useless CP Information #8: Are LGMs Overrated? Alright, clickbait title aside, how do tourist and jiangly get to 4000 rating? In chess, real life ratings cap out at around 2900, and even on online sites like Lichess, [the highest bullet players are 3300-3400, and just around 3000 for the other modes](https://lichess.org/player). Also, anecdotally, if rating is correct, the model predicts that someone who is 2940 should beat me 99.1% of the time. I have a gut feeling I beat more than 0.9% of GMs and LGMs in round 1105 and round 1108. <spoiler summary="Review on rating models if you forgot"> Rating represents win probability. In a match, for every 400 points player A is rated higher than player B, player A is 10 times more likely to win (exponentially). - If player A is rated 400 points higher than player B, then out of 11 games, player A should win 10 and player B should win 1. - If player A is rated 800 points higher than player B, then out of 101 games, player A should win 100 and player B should win 1. This can be ...
inconsequential. So this blog is complete cope. Unless... Community simulation

Full text and comments »

  • Vote: I like it
  • +211
  • Vote: I do not like it

37.
By FPythonX, history, 16 months ago, In English
Challenge: day2 Practice Smarter: 10 Codeforces Problems to Boost Your Competitive Programming Skills Contest link: [Challenge: day2](https://codeforces.me/contestInvitation/76a722ce72c61f8715a7531952347d705f5a0504) In the world of competitive programming, consistency beats intensity. You don’t need to solve 100 problems in a week — you need to solve the right problems at the right level to grow. That’s why I’ve organized 10 problems into three difficulty tiers — easy, intermediate, and advanced — so you can train smarter, not harder. Easy Level – Rating Range: 800–1200 Number of problems: 5 This range is ideal for beginners and early-stage learners. The problems here test your ability to understand problem statements, work with conditions, loops, basic math, and simple data structures like arrays or strings. These tasks may look easy, but don’t underestimate them — they lay the groundwork for everything that comes later. What to focus on: Clean implementation Under...
often require simulation, binary search, prefix sums, greedy logic, or understanding how to work

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

38.
By Ripatti, 15 years ago, translation, In English
Solutions for Codeforces Beta Round #74 <p><b>A div2</b>. In this problem you can <span id="result_box" class="short_text" lang="en"><span title="Нажмите, чтобы увидеть альтернативный перевод" class="hps">simulate the</span> <span title="Нажмите, чтобы увидеть альтернативный перевод" class="hps">process. You can consider all minutes and in </span></span><span id="result_box" class="short_text" lang="en"><span title="Нажмите, чтобы увидеть альтернативный перевод" class="hps">dependence by a color of a current cablecar decrease size of </span></span>corresponding group of students $G$ by<span id="result_box" class="short_text" lang="en"><span title="Нажмите, чтобы увидеть альтернативный перевод" class="hps"></span></span> $min(|G|,2)$, where $|G|$ is size of the group. After that you should determine the first minute $t$ in that all three groups of students will be empty. So $t+30$ is an answer. This solution works in $O(r+g+b)$.<br>[cut]<br>Also there is $O(1)$ solution. It is following formula: $ans = max(3[(R+1)/2] + 27, 3[...
="Нажмите, чтобы увидеть альтернативный перевод" class="hps">process. You can consider all minutes and

Full text and comments »

  • Vote: I like it
  • +34
  • Vote: I do not like it

39.
By MathModel, history, 13 months ago, In English
Codeforces Round 1061 (Div. 2) Editorial ### Thank you for participating ! Special Thanks to [user:hxu10,2025-10-24] for giving me the chance to write the editorial and for [user:maomao90,2025-10-24] for enhancing the editorial !. Editorial of Problems E and F are written by hxu10, and the rest are written by me. I hope they're insightful and concise, please let me hear your opinion about it or any feedback in general &#128153;. #### [problem:2156A] <spoiler summary="Hints"> <spoiler summary="Hint 1"> Since $m_1 \le m_2$, the total number of slices Alice ate is always at least as much as the total number of slices Bob ate. What's optimal construction ? </spoiler> <spoiler summary="Hint 2"> We want to try to minimize the difference between the total number of slices Alice ate and the total number of slices Bob ate. </spoiler> <spoiler summary="Hint 3"> The optimal construction is to let both $m_1$ and $m_2$ to be equals to one. The sequence of operations, denoted by $(m_1, m...
],[\mathtt{A},3]\}$$ Be careful in simulation

Full text and comments »

  • Vote: I like it
  • +159
  • Vote: I do not like it

40.
By brunomont, 6 years ago, In English
[Tutorial] Range minimum query in O(1) with linear time construction <spoiler summary="TL; DR"> Build a sparse table over blocks of size $b = 30 \geq \log{n}$. Now we only need to answer queries of size smaller than $b$. For that, simulate a minqueue of size $b$ over the array, and store a mask of the elements that are currently active in the minqueue. Let $\text{mask[r]}$ be the minqueue mask when the simulation is at position $\text{r}$. Now we can see that, if $r-l+1 \leq b$, then `query(l, r) = r - most_significant_set_bit(mask[r] & ((1<<(r-l+1))-1))`. ~~~~~ template<typename T> struct rmq { vector<T> v; int n; static const int b = 30; vector<int> mask, t; int op(int x, int y) { return v[x] < v[y] ? x : y; } int msb(int x) { return __builtin_clz(1)-__builtin_clz(x); } int small(int r, int sz = b) { return r-msb(mask[r]&((1<<sz)-1)); } rmq(const vector<T>& v_) : v(v_), n(v.size()), mask(n), t(n) { for (int i = 0, at = 0; i < n; mask[i++] = at |= 1) { at = (at<<1)&((1<<b)-1); while (at and op(i, i-msb(at&-at)) == i) at ...
$\text{mask[r]}$ be the minqueue mask when the simulation is at position $\text{r}$. Now we can see that

Full text and comments »

  • Vote: I like it
  • +258
  • Vote: I do not like it

41.
By Xellos, 12 years ago, In English
Codeforces Trainings Season 2 Episode 8: Editorial [Complete problemset + tests + original presentation of solutions.](http://www.bapc.eu/problemset.zip) [Official scoreboard](http://bapc.eu/scoreboards/bapc/), [public contest scoreboard](http://www.bapc.eu/scoreboards/public/), [used for training elsewhere](http://www.cs.ubc.ca/~acm-web/practice/2014-10-25/scores.php). Short hints first, more detailed solutions afterwards. ### A. Avoiding the Apocalypse (difficulty: medium-hard, [code](http://ideone.com/JQOMyq)) Maxflow in a suitably selected graph. Ford-Fulkerson is sufficient. <hr> The vertices of our graph need to correspond to states that one person can be in when traversing the original road network; the number of people moving in a group is then represented by flow along edges. Therefore, the most natural choice is to use vertices corresponding to states (location, time). The rules from the problem statement say that at most $c$ people can move along an edge $e=(u->v)$ in the original at any time. That me...
sorted order, so let's process them in that order. For an engineer $(r_2,r_3)$, we need to find out

Full text and comments »

  • Vote: I like it
  • +116
  • Vote: I do not like it

42.
By cry, 3 years ago, In English
Codeforces Round 887 (Div 1, Div 2) Tutorial We hope you enjoyed these problems :) This contest has been in the works for almost a year. <spoiler summary = "About the Authors"> This round was mostly made possible by problemsetters from the [CerealCodes](https://www.cerealcodes.org/) initiative! CerealCodes is an organization based in the United States dedicated to running high quality competitive programming contests. You can check out our previous contest [here](https://codeforces.me/gym/103886). </spoiler> **UPD: D1D Editorial have been updated** **UPD 2: D1D Editorial now has images by [user:EmeraldBlock,2023-08-01]. As an apology gift for being so slow, the image generator is programmatic and available [here](https://artofproblemsolving.com/texer/codeforces).** #### [problem:1853A] Problem Credits: [user:buffering,2023-06-02] Analysis: [user:buffering,2023-06-02] <spoiler summary="Hint 1"> To make $a$ not sorted, we just need to pick one index $i$ so $a_i > a_{i + 1}$. How do we do this? </spoiler...
it to simulate the process backwards. Suppose the

Full text and comments »

  • Vote: I like it
  • +183
  • Vote: I do not like it

43.
By rivalq, 5 years ago, In English
Codeforces Round #793 (Div. 2) Editorial I hope you all liked the round. Please share your feedback in the comments section. [1682A &mdash; Palindromic Indices](https://codeforces.me/contest/1682/problem/A) =============================== <spoiler summary = "Hint"> Read the statement carefully!! The given string is a **palindrome**. </spoiler> <spoiler summary = "Tutorial"> Let's remove some index $i$ from the first half of $s$ and check whether the resulting string is a palindrome or not, the other half has the same approach. The prefix of length $i-1$ already matches with the suffix of the same length because the initial string was a palindrome, so we just need to check if $t = s[i + 1 \ldots n - i + 1]$ is a palindrome. For $t$ to be a palindrome, $s_{n - i + 1}$ should be equal to $s_{i + 1}$ which was initially equal to $s_{n - i}$, again which should be equal to $s_{i + 2}$ and this goes on. Here we can see that $s_i = s_{i + 1} \ldots = s_{n - i + 1}$. So the answer is simply equal to the number ...
this process until you again reach $1$ or cross over $1$. Let the sequence obtained be $s$ i.e

Full text and comments »

  • Vote: I like it
  • +147
  • Vote: I do not like it

44.
By AlexLuchianov, 5 years ago, In English
[Tutorial]Using Segment Trees to solve Dynamic Programming problems Both segment trees and dynamic programming are common topics in competitive programming. Sometimes, they even appear together. In this blog, we will mostly use segment trees as a black-box. As such, it is not necessary (though it is highly recommended) to know segment trees to understand this blog. Let's begin. ###Longest Increasing Subsequence(LIS) _"You are given an array $v$ containing $N$ integers. Your task is to determine the longest increasing subsequence in the array, i.e., the longest subsequence where every element is larger than the previous one._ _A subsequence is a sequence that can be derived from the array by deleting some elements without changing the order of the remaining elements."_ This problem is most often solved using binary search. There are countless tutorials about this method, so I will not discuss it in detail. However, there exists a more general way to solve it using segment trees. Since we only care about the order of the elements and not a...
way to implement this solution is to maintain a matrix $dp(i, j)$ and process it line by line

Full text and comments »

  • Vote: I like it
  • +278
  • Vote: I do not like it

45.
By Dominater069, 3 years ago, In English
Codeforces Round #934 (Div1, Div2) Editorial Sorry for the delay in publishing the editorial. If anything is unclear or missing, please let me know in the comments. In all the problems, reading the hints is a must as the solution continues from there. [problem:1944A] Idea: [user:Dominater069,2024-03-17] Preparation: [user:Dominater069,2024-03-17] Editorial: [user:Dominater069,2024-03-17] <spoiler summary="Hint 1"> What is the minimum number of bridges to burn if we want to make exactly $i$ islands visitable from $1$? </spoiler> <spoiler summary="O(n) Solution"> Atleast $i \cdot (n - i)$ bridges need to burnt (the bridges connecting the $i$ reachable islands and the $n - i$ non-reachable islands). A simple $O(n)$ solution is for every $i$ from $1$ to $n$, check if $i \cdot (n - i) \le k$, in which case print $i$ and break. </spoiler> <spoiler summary="Hint 2"> What is the answer when $k \ge n - 1$. </spoiler> <spoiler summary="Hint 3"> When $k < n - 1$, is it possible to make any island non-...
out. We do this while our sequence sizes are less than $2 \cdot k$. At the end of thisprocess, $l

Full text and comments »

  • Vote: I like it
  • +109
  • Vote: I do not like it

46.
By ninja_28, history, 6 years ago, In English
CodeCraft-21 and Codeforces Round #711 (Div. 2) Editorial [problem:1498A] ================== #### [**Video Editorial**](https://www.youtube.com/watch?v=lV5cb8wh3sE) **Author and Problemsetting:** [user:ninja_28,2021-03-29] **Editorialist:** [user:sigma_g,2021-03-29] <spoiler summary="Hint"> Can you think of the simplest properties that relate a number and its sum of digits? </spoiler> <spoiler summary="Hint 2"> Note that if $X$ is a multiple of 3, then **both** $X$ as well as the sum of digits of $X$ are a multiple of 3! Can you put this property to use here? </spoiler> <spoiler summary="Hint 3"> If $X$ is a multiple of 3, then $\texttt{gcd-sum}(X) \ge 3$. Therefore, we are guaranteed that at least every third number will satisfy the constraints required by our problem $(\texttt{gcd-sum}(X) > 1)$. </spoiler> <spoiler summary="Solution"> Therefore, for the input $n$, we can simply check which one of $n$, $n+1$, and $n+2$ has its gcd-sum $> 1$, and print the lowest of them. </spoiler> <spoi...
programming to store the state of the simulation at a given time. Therefore, we can simulate the

Full text and comments »

  • Vote: I like it
  • +419
  • Vote: I do not like it

47.
By Riyad_shamiul, history, 12 months ago, In English
Useful Algorithms Beginners Should Learn Hi everyone! I’m sharing a simple and beginner-friendly roadmap that helped me understand what to learn in the early stage of competitive programming. If you are around 800–1200 rating, this list will guide you on what to practice. 1. Basic Implementation if/else loops arrays string operations Helps with Div.3 A/B problems. 2. Simulation Problems Follow the process step-by-step Very common in 800–1000 rated tasks. 3. Sorting Built-in sort Sorting + greedy idea Many problems depend only on sort + logic. 4. Two Pointers left/right pointer sliding window Useful in array/string subarray questions (1000–1200). 5. Prefix Sum prefix sum array difference array Good for range queries. 6. Binary Search search on sorted array search on answer Extremely important as difficulty increases. 7. Basic Math GCD / LCM prime checking modular arithmetic Math appears in almost every contest. 8. Greedy Algorithms step-by-step...
string operations Helps with Div.3 A/B problems. 2. Simulation Problems Follow theprocess step-by

Full text and comments »

  • Vote: I like it
  • -19
  • Vote: I do not like it

48.
By evima, 12 years ago, In English
Codeforces Round #286 Editorial (Complete) **Edit (Jan 22, 2:45 AM UTC):** Added Div1E and the editorial is now complete. I am sorry for the delay. **Edit (Jan 21, 9:45 AM UTC):** Added the explanation for Div1C/2E, and the problem setters' codes. Div1E will need several more hours. Thank you again for your patience. First, here are some statistics on this round: <table> <tr> <td>Division</td> <td>Registrants</td> <td>Participants</td> <td>A Accepted</td> <td>B Accepted</td> <td>C Accepted</td> <td>D Accepted</td> <td>E Accepted</td> </tr> <tr> <td>1</td> <td>1364</td> <td>572 (*)</td> <td>294</td> <td>199</td> <td>8</td> <td>113</td> <td>1</td> </tr> <tr> <td colspan="3">(Estimated number of AC by me)</td> <td>800 (wrong)</td> <td>500 (wrong)</td> <td>70 (FAIL)</td> <td>90 (ok)</td> <td>5 (wrong)</td> </tr> <tr> <td>2</td> <td>4016</td> <td>2028</td> <td>1355</td> <t...
painted in colors, process the queries of the following form: * Given two vertices $u_i$ and $v_i

Full text and comments »

  • Vote: I like it
  • +156
  • Vote: I do not like it

49.
By ebanner, history, 10 years ago, In English
Tutorial: Simulating recursion with a stack *Fun fact: from beginning to end this blog post took me 16 months!* This will be a tutorial on simulating recursion with a stack. I developed this tutorial after using this technique to solve [problem:472b]. Consider the following recursive definition of the `factorial()` function. ``` def factorial(n): return n*factorial(n-1) if n>1 else 1 ``` This definition is compact, concise, and mirrors the definition that appears in math textbooks very closely. In many ways it is the most natural way to define `factorial()`. However, there is a problem. For very large values of `n`, you will see that we will get a `StackOverflowError`. To understand why this is the case, you must understand that recursion is implemented in Python (and most other languages) as growing and shrinking a [stack](https://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29) in memory. For example, consider the following simulation of the computation of `factorial(3)`. ![ ](https://docs.g...
example, consider the following simulation of the computation of `factorial(3)`. ![ ](https

Full text and comments »

  • Vote: I like it
  • +6
  • Vote: I do not like it

50.
By cybersecessential, history, 15 months ago, In English
Virtualization Virtualization is the ability to create isolated, simulated environments that behave like real computers. Without virtualization, you would have to risk your primary device every time you tested a new tool, OS, or security exploit. This post builds on our cybersecurity foundations by explaining what virtualization is, how it works, the types of virtualization, and why it is critical for cybersecurity learners and professionals. Virtualization is the process of creating a simulated version of a physical system. This can be a computer, a network, or even a storage device. Virtual Machine (VM): An emulated computer running inside another computer. Host Machine: The real physical device where virtualization takes place. Guest Machine: The simulated environment (VM) that runs inside the host. Why it matters: You can run multiple operating systems, like Linux and Windows, on the same hardware — safely and independently. Types of Virtualization - Bare-Metal (Hardware) Virt...
cybersecurity learners and professionals. Virtualization is the process of creating a simulated version

Full text and comments »

  • Vote: I like it
  • -30
  • Vote: I do not like it

51.
By A2SV_Group7, history, 7 months ago, In English
A2SV G7 Contest Round #13 Editorial [Here](https://codeforces.me/contests/691516) is the contest link #### [A. PolandBall and Hypothesis](https://codeforces.me/gym/691516/problem/A) Idea and preparation: <spoiler summary="Hint"> Since $m$ only needs to be between $1$ and $1000$, can we just guess values for $m$ and check if $n \cdot m + 1$ is composite? Alternatively, is there an algebraic way to force the expression to become a perfect square? </spoiler> <spoiler summary="Solution"> There are two highly effective ways to solve this problem: **Approach 1: Brute Force** Since the constraints are extremely small ($n \le 1000$ and we only need $m \le 1000$), the maximum number we will ever check is $1000 \times 1000 + 1 \approx 10^6$. We can simply loop $m$ from 1 to 1000, calculate $val = n \cdot m + 1$, and check if $val$ is prime in $O(\sqrt{val})$ time. The first $m$ that yields a composite number is our answer. **Approach 2: $O(1)$ Math (Forcing a Square)** If we can make $n \cdot m + 1$ equal...
a graph simulation problem that introduces the concept of graph peeling. We can store the graph

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

52.
By arthur_9548, 14 months ago, In English
The Automaton Interpretation for the KMP Algorithm ## Introduction This article was started by [user:LeoRiether,2025-09-04] and concluded by me. I found his idea incredible and offered to help him finishing the text he started to write [here](https://leoriether.github.io/posts/kmp/) some years ago. I hope everyone finds it interesting! I think it's the most natural way to understand the KMP algorithm. When following the examples, you should use [user:LeoRiether,2025-09-04]'s [KMP simulator](https://leoriether.github.io/kmp-simulator/) to see for you yourself what is happening. The definitions presented here will not be so rigorous, but will instead follow a more intuitive approach. We will use examples with strings composed of characters from $a$ to $z$, but you could do the exact same with any other alphabet (like the natural numbers or whatever you want). ## Automaton? The text will assume you know what is a nondeterministic finite automaton (NFA) and a deterministic finite automaton (DFA), but I believe that an intuitive...
. ### How many states are reachable? There is potential to do better than the naivesimulation by

Full text and comments »

  • Vote: I like it
  • +106
  • Vote: I do not like it

53.
By KEPuzOfficial, 7 months ago, translation, In English
KEP Contest #19 ![ ](/predownloaded/bf/71/bf710e988bfc8f255b882437a139833ebeef7507.jpg) I invite everyone to the [contest](https://kep.uz/contests/496), which will take place on **May, 3 2026 at 14:35UTC**. Interesting problems await you in the contest. **Contest info:** - Number of problems: **9-10** - Difficulty of problems: **<= 2400** - Duration: **2:30** - Contest type: **ACM10M** - Languages: **C++, Python, C, Kotlin, Haskell, R, Nodejs, PHP, C#, Java, Rust, Go** **Prizes:** - First place – **30$ (USDT)** - Second place – **20$** - Third place – **10$** Link to the platform: https://kep.uz P.S. Registration on the platform only via Gmail/Github. **UPD** Thank you for participating. I hope you enjoyed the contest. **Results** 1. [user:ywwuyi,2026-05-03] &mdash; **10** (424) 2. [user:JahonaliX,2026-05-03] &mdash; **9** (312) 3. [user:Timosh,2026-04-13] &mdash; **9** (389) 4. [user:DigitalVest,2026-05-03] &mdash; **9** (440) 5. [user:khba,202...
simulation, output all indices with maximum shown duration. Time complexity: $O(n \log n

Full text and comments »

  • Vote: I like it
  • +40
  • Vote: I do not like it

54.
By nuredinbederu10k, history, 16 months ago, In English
A2SV Contest #24 Editorial [Here](https://codeforces.me/contestInvitation/3f06f4e1ac120eedc5edd3945965af03bdf0976a) is the link to the contest. All problems are from Codeforces' problem set [A. Life of a Flower](https://codeforces.me/gym/626626/problem/A) <spoiler summary="Solution"> We are given an array of length $n$ that represents whether Petya watered his flower each day. Each element $a_i$ is either: - $1$ → the flower **was watered** - $0$ → the flower **was not watered** The flower begins at a height of **$1$ cm** on **day 0** (before processing any input days). --- ## Simulation Logic We iterate through the array starting from index $1$ (the **second day**), and at each step, we examine the **current** element $a_i$ and the **previous** element $a_{i-1}$. There are **four possible scenarios**: --- - **Case 1:** $a_i = 1$ and $a_{i-1} = 1$ → The flower was watered **both yesterday and today** → It grows by **$5$ cm** → `height += 5` --- - **Case...
at a height of **$1$ cm** on **day 0** (before processing any input days). --- ##Simulation

Full text and comments »

  • Vote: I like it
  • -1
  • Vote: I do not like it

55.
By ashmelev, 16 years ago, translation, In English
Codeforces Beta Round #66 editorial: Problems A, B, C <div><p class="MsoNormal" style="margin-top: 12pt; margin-right: 0cm; margin-bottom: 12pt; margin-left: 0cm; "><span lang="EN-US" style="font-size: 12pt; font-family: 'Times New Roman', serif; color: black; "><b>Problem A.</b></span><span lang="EN-US" style="font-size: 12pt; font-family: 'Times New Roman', serif; color: black; "><o:p></o:p></span></p> <p class="MsoNormal" style="margin-top: 12pt; margin-right: 0cm; margin-bottom: 12pt; margin-left: 0cm; "><span lang="EN-US" style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;mso-fareast-font-family: &quot;Times New Roman&quot;;color:black;mso-ansi-language:EN-US;mso-fareast-language: RU">Let’s call the monster dimension sizes as&nbsp;<i>x<sub>1</sub>, x<sub>2</sub>, x<sub>3</sub></i>.<o:p></o:p></span></p> <p class="MsoNormal" style="margin-top: 12pt; margin-right: 0cm; margin-bottom: 12pt; margin-left: 0cm; "><span lang="EN-US" style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot...
simulation all the k actions we may quickly determine values of numbers ai

Full text and comments »

  • Vote: I like it
  • -11
  • Vote: I do not like it

56.
By A2SV_Group6, history, 9 months ago, In English
A2SV G7 — Round #2 Editorial [Here](https://codeforces.me/contests/671638) is the contest link. ### [A1. Non-alternating Deck (easy version)](https://codeforces.me/gym/671638/problem/A1) #### Approach 1 <spoiler summary="Hint 1.1"> Instead of thinking about “alternating every two steps”, define four explicit turns: - Alice1 (current is Alice, next is also Alice) - Alice2 (current is Alice, but next is Bob) - Bob1 (current is Bob, next is also Bob) - Bob2 (current is Bob, but next is Alice) These repeat in a cycle. </spoiler> <spoiler summary="Hint 1.2"> If we encode these states as numbers: - Alice1 = 0 - Alice2 = 1 - Bob1 = 2 - Bob2 = 3 Then after each step: `turn = (turn + 1) % 4` This means if turn < 2, it is Alice's turn else it is Bob's turn. </spoiler> <spoiler summary="Solution 1"> We simulate distributing cards one by one. We maintain: - cards (how many cards will be given in this turn) - cards_given (how many cards we’ve given in this tur...
="Solution 2"> We combine the optimized turn simulation from A1 – Approach 2 with the color counting

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it

57.
By Alekh0005, history, 5 months ago, In English
Learning this is day 16 of doing codeforces i really think i learn somthing new every time when my interest shifts from one thing to another this time from compitetive programming, physics simulation, c++ and quant research all things at a same time in my mind but i think my mind works only one thing at a time but it simultaneously thinking and planning for all of them, I made 2 &mdash; 3 project based on what is currently in my mind thinking as ' Cool ' and by doing all of these things i learn much more about how to make project and very important thing what is a project? i find the answer of this question by making them if i binge watch all the skills classes i might not be able to do that. I am practicing on codeforces last two weeks and i make sure that i am consistent in this process like other people, its hard to do all things at the same time but it is the way to do things like that.
shifts from one thing to another this time from compitetive programming, physicssimulation, c++ and

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it

58.
By alex_rider123, 7 months ago, In English
Freshers' CodeNite 2026 Hello everyone! Thanks for participating in the contest! Link to access the contest: [Freshers' CodeNite 2026](https://codeforces.me/contestInvitation/aa6ac1740a448d12475ec188f62b8321d4499580) Below are the hints and solutions for all the problems. --- ### [Illu Hopping](https://codeforces.me/gym/683650/problem/A) **Author:** [user:rakshit_ranka,2026-04-11] <spoiler summary="Hint"> Try to write out the pattern for small values of n and k and observe when you get stuck in invalid cycles. What are the gaps between the numbers in the invalid cycles? </spoiler> <spoiler summary="Tutorial"> There are 2 valid approaches to the problem under the given constraints. **Approach 1:** You may simulate the process of jumping and mark the visited halls using an array or set. When you reach a hall already visited check if the number of halls visited is n. **Approach 2:** This problem is a classic application of modular arithmetic. It is a known mathematical property that...
. **Approach 1:** You may simulate the process of jumping and mark the visited halls using an array or set

Full text and comments »

  • Vote: I like it
  • +24
  • Vote: I do not like it

59.
By gemechualemu, history, 8 months ago, In English
FOCUS-ASTU-TECH-COMMUNITY-CONTEST-2 Editorial #[contest:682771] Hello everyone! Welcome to the editorial for our mashup contest. We selected a mix of implementation, strings, greedy, and two-pointer problems. The goal was to strengthen logical thinking and problem-solving skills without getting bogged down in complex data structures. Below you will find hints, tutorials, and solutions for each problem. We used spoiler tags to keep things clean. Try to solve it yourself before clicking! Happy coding! ## Problem-A:[problem:682771A] **Tags:** `Implementation` `Simulation`<br> **Difficulty:** ⭐️ (Very Easy) This is a classic implementation problem that tests your ability to observe patterns in a sequence. <spoiler summary="Understanding the Problem"> #### The Goal We are given `n` magnets, each represented as: - "10" → minus-plus - "01" → plus-minus Magnets are placed one after another in a row. --- #### Key Idea - If two adjacent magnets are the same → they stick together → same group ...
:682771A] **Tags:** `Implementation` `Simulation` **Difficulty:** ⭐️ (Very Easy) This is a

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

60.
By sushmit2022, history, 7 months ago, In English
Editorial - Insomnia 2026 [A. The Oracle's Curse](https://codeforces.me/gym/682678/problem/A) ================== Author: [user:aditya1977,2026-04-27] <spoiler summary="Explanation"> <h3>Observation</h3> An alarm rings when a stock with a low starting price passes a stock with a high starting price. Since all stocks go up by exactly $1$ every day, a lower stock can only pass a higher stock if the higher one hits its maximum limit and stops growing. Once it passes, it stays ahead forever. Because the total number of alarms only goes up over time (it never goes back down), we can easily use <b>Binary Search</b>. In coding terms, when a smaller starting value overtakes a larger one, we call this an <b>inversion</b>. <hr> <h3>Definition</h3> Let $N$ be the number of stocks and $g$ be the target alarms. First, we sort all stocks by their starting prices $s_i$. Each stock is stored as a pair: $$ E_i = (s_i, u_i) $$ For any guessed day $D$, the new projected price $P_i$ of the $i$-th stock...
Efficiently We process $A$ from left to right. For current compressed value $x$: $less=query(x

Full text and comments »

  • Vote: I like it
  • +13
  • Vote: I do not like it

61.
By willy108, history, 3 years ago, In English
Teamscode Spring 2024 Contest Official Editorial Sorry for the long wait. These problems were brought to you by [user:esomer,2024-04-05], [user:danx,2024-04-05], [user:dutin,2024-04-05], [user:jay_jayjay,2024-04-05], [user:oursaco,2024-04-05], [user:superhelen,2024-04-05], [user:thehunterjames,2024-04-05], [user:willy108,2024-04-05], and [user:yash_9a3b,2024-04-05]. Also, massive thanks to [user:omeganot,2024-04-05] for his [unofficial editorial](https://codeforces.me/blog/omeganot) (which was posted a lot sooner than ours). [Novice A/](https://codeforces.me/gym/105066/problem/A)[Advanced A: It's Time to Submit](https://codeforces.me/gym/105067/problem/A) ================== <spoiler summary="Solution"> Both "YES" and "NO" are consistent answer (as long as exactly one of them is the answer). If you print "YES" and get AC, you are getting AC by printing the sample output. If you print "NO" and get AC, you are getting AC by not printing the sample output. Never assume just because the carrot is big ... the sample out...
process with a brute force, figuring out which ice creams were eaten on day $i$. Finally, we can

Full text and comments »

  • Vote: I like it
  • +42
  • Vote: I do not like it

62.
By HailOtg, history, 2 months ago, In English
Codewarts Editorial Congratulations to all the wizards and witches who participated in Codewarts! Here is the official editorial for all the problems. Round 1 ------------------ <spoiler summary="Problem-A: Tom Riddle's Diary"> <spoiler summary="Hint-1"> Since $N$ is always even, try visualizing the array as $N/2$ non-overlapping pairs of adjacent elements.<br> $(A_1,A_2), (A_3,A_4), \dots$ </spoiler> <spoiler summary="Hint-2"> If every pair must sum to a multiple of $P$, what must the total sum $M$ be a multiple of? Given that numbers must be positive, what is the absolute minimum possible total sum? </spoiler> <spoiler summary="Hint-3"> To build the array, try repeating a simple pair like $(1,P-1)$ for most of the array, and put all the remaining required sum into the very last element. </spoiler> <spoiler summary="Solution"> **When to print NO:** - Because $N$ is even, we can split the array into exactly $N/2$ disjoint pairs. The problem requires every adjacent pai...
n)$ The simulation after sorting takes: **Time Complexity:** $\mathcal{O}(n)$ Therefore

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

63.
By MohammadParsaElahimanesh, 11 months ago, In English
Codeforces Global Round 31 Salam ! Here is the editorial for [Codeforces Global Round 31](https://codeforces.me/contest/2180). We hope you find these solutions helpful. We also have prepared a special editorial with step by step hint, examples, tables, and walkthroughs which is available [here](https://repovive.com/editorial/codeforces-global-round-31). #### [problem:2180A] **Idea:** [user:Amirrzwm,2025-12-18], [user:MohammadParsaElahimanesh,2025-12-18] &mdash; **Preparation:** [user:MohammadParsaElahimanesh,2025-12-18] <spoiler summary="Solution"> <spoiler summary="Simple Simulation (Brute force)"> Since constraints are small, we can simulate the spins directly: - Start from section $a$. - Move the pointer by adding $b$ modulo $l$ repeatedly. - Stop when we return to a previously visited section. - Among all visited sections, select the section with the highest prize. It runs in $\mathcal{O}(l)$ as we mark each section at most once. </spoiler> <spoiler summary="Mathematical Solutio...
,2025-12-18]

Full text and comments »

64.
By Dambola, history, 8 years ago, In English
SESCOMP Marathon 2018 — Federal University of Ceará — TUTORIAL Problem A – Academia ------------------ #### ENGLISH This is a Dynamic programming (and/or simulation) question. It's a derivative from the classic Knapsack Problem. First we do vector, with size from $0$ to $T_{max}$ $(T_{max}+1)$, where we can simulate "how heavy is our bag", that is, how much time we spend. Initially the vector is filled with zeros, because we have no Power of Muscle. For every exercise we will do the following: 1) We are going to see the vector between $[0, T_{max} - T_{exercise}]$, this is our storage vector for every exercise. 2) For $t_i$ in $[0,T_{max} - T_{exercise}]$ we will propagate the sum of Power of Muscle from $vector[t_i]$ and $P_{exercise}$ to the next time. 3) Doing: $vector[t_{i} + T_{exercise}] = max(vector[t_i] + P_{exercise}, vector[t_{i} + T_{exercise}])$ OBS: Do $ti$ in $[0,T_{max} - T_{exercise}]$ goes from right to left to not have a overlapping of Power of Muscle. At the end, search for the higher value of $...
simulation) question. It's a derivative from the classic Knapsack Problem. First we do vector

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it