Peanut Packing A man is running a super market and he observes the pattern of customer buying peanuts in packs of 1 kg, 2 kgs, 3 kgs till N kgs. So based on the buying pattern and his observation he can price the packs of 1 kg, 2 kgs, ... N kgs at rupees P(1), P(2), P(3), ... P(N) respectively. What is the maximum revenue he can earn when selling N kgs of peanuts based on the given pricing? Input Format: The first line contains N. The second line contains the integer value denoting the price for 1 kg pack, 2 kgs pack till N kgs pack with each value separated by a space. Output Format: The first line contains the maximum revenue he can earn by packing and selling the N kgs peanuts based on the given pricing. Boundary Conditions: 1 <= N <= 999 Example Input/Output 1: Input: 4 120 250 360 490 Output: 500 Explanation: While selling 4 kgs of peanuts, the maximum revenue of Rs.500 is obtained when he packs the 4 kgs as 2 kgs + 2kgs and sells them at Rs. 250 each. Example Input/O...
// C++ program to find the smallest number which greater than a given number // and has same set of digits as given number #include <iostream> #include <cstring> #include <algorithm> using namespace std; // Utility function to swap two digits void swap(char *a, char *b) { char temp = *a; *a = *b; *b = temp; } // Given a number as a char array number[], this function finds the // next greater number. It modifies the same array to store the result void findNext(char number[], int n) { int i, j; // I) Start from the right most digit and find the first digit that is // smaller than the digit next to it. for (i = n-1; i > 0; i--) if (number[i] > number[i-1]) break; // If no such digit is found, then all digits are in descending order // means there cannot be a greater number with same set of digits if (i==0) { cout << "Next number is not possible"; return; } // II) Find the smallest digit on rig...
Objects are best when you want to organize based on data labels. When you read a newspaper, you likely do not read it front to back, page by page. You flip to a certain section based on the section’s … https://medium.freecodecamp. com/javascript-arrays-and- objects-are-just-like-books- and-newspapers-6e1cbd8a1746
Comments
Post a Comment