
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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 Articles
- 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\n
- Find Sum of pair from two arrays with maximum sum in C++
- Maximum sum of n consecutive elements of array in JavaScript
- 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++
- Arrange the following elements in increasing order of their atomic radii :Li, Be, F, N
- Sum of special triplets having elements from 3 arrays in C++
- Python Program to extracts elements from a list with digits in increasing order
- Maximum OR sum of sub-arrays of two different arrays in C++
- Find Maximum Sum Strictly Increasing Subarray in C++
- Maximum Sum Increasing Subsequence | DP-14 in C++
- Maximum Sum of Products of Two Arrays in C++
- Generating combinations from n arrays with m elements in JavaScript

Advertisements