Contents

**Largest Gold Ingot Codevita 9 Solution**

Ramesh is a goldsmith, who brought a large number of gold ingot each of different length(L) but equal breadth(B) and height(H). He wants to weld the ingots of same length with each other. He tasks his new employee, Akash, to weld the ingots of same length with each other. But Akash forgot that he had to weld the ingots of same length, instead he welded the ingots in a random manner.

Later Ramesh found out what he had done. He then ordered Akash to cut the welded ingot such that a cuboid with the largest volume from the welded gold ingot is obtained.

Find the volume of summation of gold ingots minus volume of the largest cuboid.

**Constraints**

0 < G < 10^5

**Input**

- First Line contains one integer G, denoting number of gold ingots
- Second line contains two space separated integers B and H, where B denotes the breadth and H denotes the height of individual ingot
- Third line contains G space separated integers, denoting the length of the individual gold ingots that are welded together in adjacent manner

**Output**

An integer corresponding to the volume of summation of gold ingots minus volume of the largest cuboid, mod 10^9+7.

**Time Limit**

1

**Examples**

**Example 1**

**Input**

7

1 1

6 7 3 4 5 1 3

**Output**

14

**Explanation**

Total volume of shaded region is 15 and the total volume is 29. So the volume of summation of gold ingots minus largest cuboid obtained is 14, since the height is 1 and breadth is 1.

**Example 2**

**Input**

7

1 2

1 2 6 4 5 3 4

**Output**

20

**Explanation**

The volume of summation of gold ingots minus largest cuboid obtained is 20, since the height is 2 and breadth is 1.

**SOLUTION**

**Program:** Largest Gold Ingot Codevita 9 Solution in C++

```
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
long long int n, sum = 0;
cin >> n;
long long int a, b, m = pow(10, 9) + 7;
cin >> a >> b;
int arr[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
sum = sum + arr[i];
}
long long int res = 0, ans = 0;
stack<int> s;
for (int i = 0; i < n; i++)
{
while (s.empty() == false and arr[i] <= arr[s.top()])
{
long long int tp = s.top();
s.pop();
res = arr[tp] * (s.empty() ? i : (i - s.top() - 1));
ans = max(ans % m, res);
}
s.push(i);
}
while (s.empty() == false)
{
long long int tp = s.top();
s.pop();
res = arr[tp] * (s.empty() ? n : (n - s.top() - 1));
ans = max(ans % m, res);
}
cout << ((sum % m - ans % m) % m * a % m * b % m) % m;
}
```

**Codevita Season 9 All Questions Solution**

*Even Odd Codevita 9 Solution**Largest Gold Ingot Codevita 9 Solution**Fill the Cube Codevita 9 Solution**Logic for Single Lane Highway Codevita 9**Faulty Keyboard Codevita 9 Solution 2020**Signal Connection Codevita 9 Solution 2020**Closing Value Codevita 9 Solution**CodeVita season 9 Zone 2 All Solutions**Railway Station Codevita 9 Solution**Count Pairs Codevita 9 Solution**7 X 7 Codevita 9 Solution**Tennis Score codevita 9 Solution**Unlocker Codevita 9 Solution**Path through graph Codevita 9 Solution**Secret Word Codevita 9 Solution**3 Palindrome Codevita 9 Solution**Max Sum Codevita 9 Solution**Equalize Weights Codevita 9 Solution**Binary Equivalent Codevita 9 Solution**String Word Codevita 9 Solution**4 Particles Codevita 9 Solution**String Pair Codevita 9 Solution**Corona Virus Codevita 9 Solutions**Factor of 3 Codevita 9 Solutions**Single Lane Highway Codevita 9 Solution*