## [SOLUTION] Off by One solution codeforces – There are nn points on an infinite plane, 2021

Off by One solution codeforces There are nn points on an infinite plane. The ii-th point has coordinates (xi,yi)(xi,yi) such that xi>0xi>0 and yi>0yi>0. The coordinates are not necessarily integer. In one move you perform the following operations: choose two points aa and bb (a≠ba≠b); move point aa from (xa,ya)(xa,ya) to either (xa+1,ya)(xa+1,ya) or (xa,ya+1)(xa,ya+1); move point bb from (xb,yb)(xb,yb) to either (xb+1,yb)(xb+1,yb) or (xb,yb+1)(xb,yb+1); remove points aa and bb. However, the move can only be performed if there exists a line that passes through the new coordinates of aa, … Read more

## [SOLUTION] Maximum Sum of Products solution codeforces – You are given two integer arrays aa and bb of length nn. 2021

Maximum Sum of Products solution codeforces You are given two integer arrays aa and bb of length nn. You can reverse at most one subarray (continuous subsegment) of the array aa. Your task is to reverse such a subarray that the sum ∑i=1nai⋅bi∑i=1nai⋅bi is maximized. Input :  The first line contains one integer nn (1≤n≤50001≤n≤5000). The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1071≤ai≤107). The third line contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤1071≤bi≤107). Output : Print single integer — maximum possible sum after … Read more

## [SOLUTION] Berland Regional solution codeforces – Polycarp is an organizer of a Berland ICPC regional event – 2021

Berland Regional solution codeforces Polycarp is an organizer of a Berland ICPC regional event. There are nn universities in Berland numbered from 11 to nn. Polycarp knows all competitive programmers in the region. There are nn students: the ii-th student is enrolled at a university uiui and has a programming skill sisi. Polycarp has to decide on the rules now. In particular, the number of members in the team. Polycarp knows … Read more

## [SOLUTION] The Cake Is a Lie solution codeforces – There is a n×mn×m grid. You are standing at cell (1,1)(1,1)

The Cake Is a Lie solution codeforces There is a n×mn×m grid. You are standing at cell (1,1)(1,1) and your goal is to finish at cell (n,m)(n,m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x,y)(x,y). You can: move right to the cell (x,y+1)(x,y+1) — it costs xx burles; move down to the cell (x+1,y)(x+1,y) — it costs yy burles. Can … Read more

## [SOLUTION] Red and Blue Beans solution codeforces – You have rr red and bb blue beans – 2021

Red and Blue Beans solution You have rr red and bb blue beans. You’d like to distribute them among several (maybe, one) packets in such a way that each packet: has at least one red bean (or the number of red beans ri≥1ri≥1); has at least one blue bean (or the number of blue beans bi≥1bi≥1); the number of red and blue beans should differ in … Read more

## Cleaning Drive solution – There is a hallway of length N−1N−1 and you have MM workers to clean the floor

Cleaning Drive solution There is a hallway of length N−1N−1 and you have MM workers to clean the floor. Each worker is responsible for segment [Li,Ri][Li,Ri], i.e., the segment starting at LiLi and ending at RiRi. The segments might overlap. Every unit of length of the floor should be cleaned by at least one worker. A worker can clean 11 unit of length of the floor in 11 unit of time and … Read more

## Chef and Hills solution – Chefland is a 1D1D city where each of the NN houses

Chef and Hills solution Chefland is a 1D1D city where each of the NN houses is located at a distinct positive integer coordinate A1,A2,…ANA1,A2,…AN. The chef is planning to create KK hills in the city. Note that two hills cannot be present at the same location but the location of hills and houses can overlap and each hill will also be at any integer (positive, negative or zero) coordinate. Chef … Read more

## Maximum Size solution – Chef is playing an easier variation of the board game ‘Risk’ with his friend Mike 2021

Maximum Size solution Chef is playing an easier variation of the board game ‘Risk’ with his friend Mike. There is an N∗MN∗M grid, depicting the world map. Each cell of the grid is either 11 or 00 where 11 denotes that there is land on this cell, while 00 denotes water. In a turn, a player can capture an uncaptured cell that has land, and keep capturing neighbouring cells that … Read more

## Thief and Police solution – There is an NN by MM grid. A thief is trying to escape from a policeman 2021

Thief and Police solution There is an NN by MM grid. A thief is trying to escape from a policeman. The thief is currently in cell (x,y)(x,y) in the grid, while the policeman is in cell (a,b)(a,b). Cells are numbered from 11 to NN, top to bottom, and 11 to MM, left to right. Both of them are at different cells initially. Thief and Police solution Both of them take turns alternatively. First … Read more

## Hiring Test solution – A company conducted a coding test to hire candidates. 2N candidates appeared for the test

Hiring Test solution A company conducted a coding test to hire candidates. NN candidates appeared for the test, and each of them faced MM problems. Each problem was either unsolved by a candidate (denoted by ‘U’), solved partially (denoted by ‘P’), or solved completely (denoted by ‘F’). To pass the test, each candidate needs to either solve XX or more problems completely, or solve (X−1)(X−1) problems completely, and YY or … Read more