Problem Description: There are N jugs on a table and each jug has a capacity C[i]. Each jug will be filled with water such that the amount of water from Jug 1 to Jug N will be in non-increasing order. i.e. if Jug i has A[i] amount of water in it the A[i] >= A[i+1] for 1 <= i < N. What is the maximum amount of water in total that can be poured in all the jugs?
Input format: The first line contains T, number of test cases. For each test case, First line contains N, number of Jugs. Second line contains N space separated integers, C[i].
Output format: For each test case print the maximum amount of water that can be poured in the jugs in a new line.
My Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int testCases;
cin>>testCases;
while(testCases--)
{
int jugs, answer = 0, minCapacity = 0, inputCapacity;
cin >> jugs;
cin >> inputCapacity;
minCapacity = inputCapacity;
answer = inputCapacity;
for(int i = 1; i < jugs; i++)
{
cin >> inputCapacity;
if(inputCapacity < minCapacity )
{
minCapacity = inputCapacity;
}
answer = answer + minCapacity;
}
cout << answer << "\n";
}
return 0;
}