Latest Posts in Codeforces

CreateBlog Picture

C. Raspberries Solution | Codeforces Round 905 (Div. 3)

Raunit Verma- inCodeforces

You are given an array of integers π‘Ž1,π‘Ž2,…,π‘Žπ‘› and a number π‘˜ (2β‰€π‘˜β‰€5 ). In one operation, you can do the following: Choose an index 1≀𝑖≀𝑛 , Set π‘Žπ‘–=π‘Žπ‘–+1 . Find the minimum number of operations needed to make the product of all the numbers in the array π‘Ž1β‹…π‘Ž2β‹…β€¦β‹…π‘Žπ‘› divisible by π‘˜ .

CreateBlog Picture

B. Playing in a Casino | Codeforces Solution | Codeforces Round 861 (Div. 2)

Raunit Verma- inCodeforces

Galaxy Luck, a well-known casino in the entire solar system, introduces a new card game. In this game, there is a deck that consists of 𝑛 cards. Each card has π‘š numbers written on it. Each of the 𝑛 players receives exactly one card from the deck. Then all players play with each other in pairs, and each pair of players plays exactly once. Thus, if there are, for example, four players in total, then six games are played: the first against the second, the first against the third, the first against the fourth, the second against the third, the second against the fourth and the third against the fourth.

CreateBlog Picture

A. Reverse a Substring | Codeforces Solution | Educational Codeforces Round 63 (Rated for Div. 2)

Raunit Verma- inCodeforces

You are given a string 𝑠 consisting of 𝑛 lowercase Latin letters. Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6 ), but "aa" or "d" aren't substrings of this string. So the substring of the string 𝑠 from position 𝑙 to position π‘Ÿ is 𝑠[𝑙;π‘Ÿ]=𝑠𝑙𝑠𝑙+1β€¦π‘ π‘Ÿ . You have to choose exactly one of the substrings of the given string and reverse it (i. e. make 𝑠[𝑙;π‘Ÿ]=π‘ π‘Ÿπ‘ π‘Ÿβˆ’1…𝑠𝑙 ) to obtain a string that is less lexicographically. Note that it is not necessary to obtain the minimum possible string.

CreateBlog Picture

B. Sequence Game | Codeforces Solution | Codeforces Round 894 (Div. 3)

Raunit Verma- inCodeforces

Tema and Vika are playing the following game. First, Vika comes up with a sequence of positive integers π‘Ž of length π‘š and writes it down on a piece of paper. Then she takes a new piece of paper and writes down the sequence 𝑏 according to the following rule: First, she writes down π‘Ž1 . Then, she writes down only those π‘Žπ‘– (2β‰€π‘–β‰€π‘š ) such that π‘Žπ‘–βˆ’1β‰€π‘Žπ‘– . Let the length of this sequence be denoted as 𝑛 .

CreateBlog Picture

D. Plus Minus Permutation | Codeforces Solution | Codeforces Round 895 (Div. 3)

Raunit Verma- inCodeforces

You are given 3 integers β€” 𝑛 , π‘₯ , 𝑦 . Let's call the score of a permutation† 𝑝1,…,𝑝𝑛 the following value: (𝑝1β‹…π‘₯+𝑝2β‹…π‘₯+…+π‘βŒŠπ‘›π‘₯βŒ‹β‹…π‘₯)βˆ’(𝑝1⋅𝑦+𝑝2⋅𝑦+…+π‘βŒŠπ‘›π‘¦βŒ‹β‹…π‘¦) In other words, the score of a permutation is the sum of 𝑝𝑖 for all indices 𝑖 divisible by π‘₯ , minus the sum of 𝑝𝑖 for all indices 𝑖 divisible by 𝑦 . You need to find the maximum possible score among all permutations of length 𝑛 . For example, if 𝑛=7 , π‘₯=2 , 𝑦=3 , the maximum score is achieved by the permutation [2,6⎯⎯,1⎯⎯,7⎯⎯,5,4⎯⎯⎯⎯,3] and is equal to (6+7+4)βˆ’(1+4)=17βˆ’5=12 .

CreateBlog Picture

B. Olya and Game with Arrays | CodeForces Solution | Codeforces Round 892 (Div. 2)

Raunit Verma- inCodeforces

Artem suggested a game to the girl Olya. There is a list of 𝑛 arrays, where the 𝑖 -th array contains π‘šπ‘–β‰₯2 positive integers π‘Žπ‘–,1,π‘Žπ‘–,2,…,π‘Žπ‘–,π‘šπ‘– . Olya can move at most one (possibly 0 ) integer from each array to another array. Note that integers can be moved from one array only once, but integers can be added to one array multiple times, and all the movements are done at the same time.

CreateBlog Picture

B. Fair Numbers | Codeforces | Technocup 2021 - Elimination Round 3 | Solution

Raunit Verma- inCodeforces

We call a positive integer number fair if it is divisible by each of its nonzero digits. For example, 102 is fair (because it is divisible by 1 and 2 ), but 282 is not, because it isn't divisible by 8 . Given a positive integer 𝑛 . Find the minimum integer π‘₯ , such that 𝑛≀π‘₯ and π‘₯ is fair.

CreateBlog Picture

B. Monsters | Codeforces Solution | Educational Codeforces Round 152 (Rated for Div. 2)

Raunit Verma- inCodeforces

Monocarp is playing yet another computer game. And yet again, his character is killing some monsters. There are 𝑛 monsters, numbered from 1 to 𝑛 , and the 𝑖 -th of them has π‘Žπ‘– health points initially.

CreateBlog Picture

B. Divan and a New Project | Codeforces Solution | Codeforces Round 757 (Div. 2)

Raunit Verma- inCodeforces

The company "Divan's Sofas" is planning to build 𝑛+1 different buildings on a coordinate line so that: the coordinate of each building is an integer number; no two buildings stand at the same point. Let π‘₯𝑖 be the coordinate of the 𝑖 -th building. To get from the building 𝑖 to the building 𝑗 , Divan spends |π‘₯π‘–βˆ’π‘₯𝑗| minutes, where |𝑦| is the absolute value of 𝑦 .

CreateBlog Picture

A. Unit Array | Codeforces Solution | Codeforces Round 879 (Div. 2)

Raunit Verma- inCodeforces

Given an array π‘Ž of length 𝑛 , which elements are equal to βˆ’1 and 1 . Let's call the array π‘Ž good if the following conditions are held at the same time: π‘Ž1+π‘Ž2+…+π‘Žπ‘›β‰₯0 ; π‘Ž1β‹…π‘Ž2β‹…β€¦β‹…π‘Žπ‘›=1 . In one operation, you can select an arbitrary element of the array π‘Žπ‘– and change its value to the opposite. In other words, if π‘Žπ‘–=βˆ’1 , you can assign the value to π‘Žπ‘–:=1 , and if π‘Žπ‘–=1 , then assign the value to π‘Žπ‘–:=βˆ’1 .

CreateBlog Picture

D. Three Activities | Codeforces Solution | Codeforces Round 916 (Div. 3)

Raunit Verma- inCodeforces

Winter holidays are coming up. They are going to last for 𝑛 days. During the holidays, Monocarp wants to try all of these activities exactly once with his friends: go skiing; watch a movie in a cinema; play board games. Monocarp knows that, on the 𝑖 -th day, exactly π‘Žπ‘– friends will join him for skiing, 𝑏𝑖 friends will join him for a movie and 𝑐𝑖 friends will join him for board games.

CreateBlog Picture

A. Valeriy and Deque Codeforces Solution | Codeforces Round 569 (Div. 1)

Raunit Verma- inCodeforces

Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with 𝑛 elements. The 𝑖 -th element is π‘Žπ‘– (𝑖 = 1,2,…,𝑛 ). He gradually takes the first two leftmost elements from the deque (let's call them 𝐴 and 𝐡 , respectively), and then does the following:

CreateBlog Picture

B. Array merging | CodeForces Solution | Codeforces Round 875 (Div. 2)

Raunit Verma- inCodeforces

You are given two arrays π‘Ž and 𝑏 both of length 𝑛 . You will merge† these arrays forming another array 𝑐 of length 2⋅𝑛 . You have to find the maximum length of a subarray consisting of equal values across all arrays 𝑐 that could be obtained.

CreateBlog Picture

C. Ski Resort | CodeForces Solution | Codeforces Round 878 (Div. 3)

Raunit Verma- inCodeforces

Dima Vatrushin is a math teacher at school. He was sent on vacation for 𝑛 days for his good work. Dima has long dreamed of going to a ski resort, so he wants to allocate several consecutive days and go skiing. Since the vacation requires careful preparation, he will only go for at least π‘˜ days.

CreateBlog Picture

B. Shoe Shuffling | Codeforces Solution | CodeCraft-22 and Codeforces Round 795 (Div. 2)

Raunit Verma- inCodeforces

A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object. There are 𝑛 students in the class, and you are given an array 𝑠 in non-decreasing order, where 𝑠𝑖 is the shoe size of the 𝑖 -th student. A shuffling of shoes is valid only if no student gets their own shoes and if every student gets shoes of size greater than or equal to their size.