Computer Science, asked by Sahanapavi99, 3 months ago

Alex has been preparing a box for handicraft.
The box consists of N pieces of stones with each
stone having a certain weight assigned to it.
Each stone in the box will carry a different
weight. This means no two stones can have the
same weight.
Alex wants to do this by making minimal
changes in the original weight of the stones,
making each stone weigh at least as much as its
original weight.Write a c program to Find the minimum total weight that he can set
for the box.
Note: Stone weights are not in float value.​

Answers

Answered by brajeshkumardwivedi4
2

Answer:

this answer gives who this this question

Explanation:

hope all goes smoothly and that the intended recipients and fair play of mathematics- I have a great time in democratic Republic and fair and reasonable

Answered by singhsumit8679207176
1

Answer:

#include <iostream>

using namespace std;

 

int minSum(int arr[], int n)

{

   int sum = arr[0], prev = arr[0];

 

   for (int i = 1; i < n; i++) {

       if (arr[i] <= prev) {

           prev = prev + 1;

           sum = sum + prev;

       }

       else {

           sum = sum + arr[i];

           prev = arr[i];

       }

   }

 

   return sum;

}

 

int main()

{

   int n;

   cin>>n;

   int a[n];

   for(int i=0;i<n;i++)

   cin>>a[i];

   

   cout << minSum(a, n) << endl;

   return 0;

}

Explanation:

Similar questions