

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maximum sum of increasing order elements from n arrays in C++
In this tutorial, we will be discussing a program to find maximum sum of increasing order elements from n arrays.
For this we will be provided with N arrays of M size. Our task is to find the maximum sum by selecting one element from each array such that element from the previous array is smaller than the next one.
Example
#include <bits/stdc++.h> #define M 4 using namespace std; //calculating maximum sum by selecting //one element int maximumSum(int a[][M], int n) { for (int i = 0; i < n; i++) sort(a[i], a[i] + M); int sum = a[n - 1][M - 1]; int prev = a[n - 1][M - 1]; int i, j; for (i = n - 2; i >= 0; i--) { for (j = M - 1; j >= 0; j--) { if (a[i][j] < prev) { prev = a[i][j]; sum += prev; break; } } if (j == -1) return 0; } return sum; } int main() { int arr[][M] = { {1, 7, 3, 4}, {4, 2, 5, 1}, {9, 5, 1, 8} }; int n = sizeof(arr) / sizeof(arr[0]); cout << maximumSum(arr, n); return 0; }
Output
18
- Related Questions & Answers
- Maximum sum of increasing order elements from n arrays in C++ program
- Maximum sum by picking elements from two arrays in order in C++ Program
- Maximum Sum Increasing Subsequence
- Maximum sum of n consecutive elements of array in JavaScript
- Find Sum of pair from two arrays with maximum sum in C++
- Sum of special triplets having elements from 3 arrays in C++
- Maximum sum from three arrays such that picking elements consecutively from same is not allowed in C++
- Maximum array from two given arrays keeping order same in C++
- Find Maximum Sum Strictly Increasing Subarray in C++
- Maximum Sum Increasing Subsequence | DP-14 in C++
- Maximum OR sum of sub-arrays of two different arrays in C++
- Maximum Sum of Products of Two Arrays in C++
- Generating combinations from n arrays with m elements in JavaScript
- Python Program to extracts elements from a list with digits in increasing order
- Maximum sum of elements from each row in the matrix in C++
Advertisements