Found 7197 Articles for C++

C++ code to count maximum banknotes bank can gather

Arnab Chakraborty
Updated on 30-Mar-2022 14:23:19

278 Views

Suppose we have three numbers k, l and m, and have another array A with n elements. A robber failed to rob a bank but had managed to open all the safes of a bank. The blank client decides to take advantage of this failed robbery and steal some money from the safes. In a line there are many safes. There are n banknotes left in all the safes in total. The i-th banknote is in safe A[i]. The bank employee is now at safe k. There are two security guards, one of which guards the safe l such that ... Read More

C++ code to find winner of math contest

Arnab Chakraborty
Updated on 30-Mar-2022 14:19:42

421 Views

Suppose we have two arrays P and T of size n. And have another number c. Amal and Bimal are going to participate one math contest. There are n problems. The ith problem has initial score P[i], and takes T[i] to solve it. P and T both are sorted in increasing order. Here c is the constant for loosing points. If a problem is submitted at time x (x minutes after starting the contest), it gives max(0, P[i] - c*x) points. Amal is going to solve problems in order 1, 2, ... n and Bimal is going to solve them ... Read More

C++ code to count children who will get ball after each throw

Arnab Chakraborty
Updated on 30-Mar-2022 14:16:35

1K+ Views

Suppose we have a number n. Few kids are standing on a circle. They are numbered from 1 to n, they are in clockwise order and the child number 1 is holding the ball. First the child number 1 throws the ball to the next one clockwise, Then the child number 2 throws the ball to the next but one child, (to the child number 4), then the fourth child throws the ball to the child number 7 and so on. When a ball is thrown it may pass the beginning of the circle. Not all the children get the ... Read More

C++ code to find minimum time needed to do all tasks

Arnab Chakraborty
Updated on 30-Mar-2022 14:14:31

504 Views

Suppose we have an array A with n elements, and two other arrays k and x. The ith task takes A[i] time to complete. The given A is sorted in non-decreasing fashion. Amal takes at most k tasks and do each of them in x units of time instead of A[i]. (x < minimum of all A[i]). We have to find the minimum time needed to complete Amal's task. Amal cannot do more than one task simultaneously.So, if the input is like A = [3, 6, 7, 10]; k = 2; x = 2, then the output will be 13, ... Read More

C++ code to count who have declined invitation

Arnab Chakraborty
Updated on 30-Mar-2022 14:11:40

183 Views

Suppose we have an array A with n elements, and all elements are distinct. There are n of the onsite finalists who can join a company, their qualifying ranks are present in array A. We have to find the minimum possible number of contestants that declined the invitation to compete onsite in the final round. There will be 25 person from which, few have accepted or few declined.So, if the input is like A = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28], ... Read More

C++ code to count columns for calendar with month and first day

Arnab Chakraborty
Updated on 30-Mar-2022 14:08:43

339 Views

Suppose we have two numbers m and d. Consider a calendar where week days are represented as columns and rows are current days. We want to know how many columns in the calendar should have given the month m and the weekday of the first date of that month d (Assuming that the year is not leap-year).So, if the input is like m = 11; d = 6, then the output will be 5, because 1-st November is Saturday and 5 columns is enough.StepsTo solve this, we will follow these steps −Define an array a of size: 13 := { ... Read More

C++ code to check query for 0 sum

Arnab Chakraborty
Updated on 30-Mar-2022 13:58:37

145 Views

Suppose we have an array A with n elements, the elements are in range -1 to 1. And have another array of pairs for m queries Q like Q[i] = (li, ri). The response to the query will be 1 when the elements of array a can be rearranged so as the sum Q[li] + ... + Q[ri] = 0, otherwise 0. We have to find answers of all queries.So, if the input is like A = [-1, 1, 1, 1, -1]; Q = [[1, 1], [2, 3], [3, 5], [2, 5], [1, 5]], then the output will be [0, ... Read More

C++ code to get maximum profit by house making

Arnab Chakraborty
Updated on 30-Mar-2022 13:56:03

292 Views

Suppose we have two numbers n and h, and another array of m triplets T, where T[i] = (li, ri, xi). On a road, there are n places where we can make houses. The spots are numbered as 1 to n. The house height can be from 0 to h. In each spot if we make a house of height k, we will gain k^2 amount of money from it. There are m zone restrictions. The ith restriction says: The tallest house from spots li to ri, must be at most xi. We want to make houses to maximize our ... Read More

C++ code to check given matrix is good or not

Arnab Chakraborty
Updated on 30-Mar-2022 13:15:01

289 Views

Suppose we have one n x n matrix. The matrix is said to be a good matrix where every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. We have to check whether given matrix is good or not.So, if the input is like112231641Then the output will be True, because the 6 in the bottom left corner is valid because when the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 ... Read More

C++ code to check water pouring game has all winner or not

Arnab Chakraborty
Updated on 30-Mar-2022 13:08:18

267 Views

Suppose we have an array A with n elements and have another number s. There is one empty water mug and n non-empty water mugs on the table. In a game, there are few players. In each move, a player takes a non-empty mug of water and pours all water from it into the cup. If it overfills, the player will lost. We have to check whether all of them will be winner or not (the cup will not overfill). If one up is already filled completely, the next player will not play his/her move. Here s is the capacity ... Read More

Advertisements