For this Question: There are N Power Stones in Morag represented in an array PowerStones, where PowerStones[i] is the power of ith stone.
You are one of the guardians, your task is to choose two stones and smash them together. Suppose you have stones with power x and y with x <= y then the result of the smash is :
a. If x == y, then both stones get destroyed.
b. If x != y, then the power of stone x is destroyed and the
stone y has a new power y - x.
At the end of the task, there is at most one stone left. Print the smallest possible power of the left stone.First Line contains an integer N, length of array PowerStones
Second- line contains N space- separated integers of the array

Constraints :
1 <= N <= 30
1 <= PowerStones[i] <= 100Print the smallest possible power of the left stone 

Note:-
If the size of the array becomes zero then 0 will be considered as the smallest possible power.Sample Input:-
6
2 7 4 1 8 1

Sample Output:-
1

Explanation:
We can combine 2 and 4 to get 2, so the array converts to
[2, 7, 1, 8, 1] then,
we can combine 7 and 8 to get 1, so the array converts to
[2, 1, 1, 1] then,
we can combine 2 and 1 to get 1, so the array converts to [1, 1, 1]
then,
we can combine 1 and 1 to get 0, so the array converts to [1],
then that's the optimal value

Sample Input:-
5
2 1 1 1 1

Sample Output:-
0, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int laststonepower(vector<int>& stones) {
int sum=0, n=stones.size();
for(int i=0; i<n; i++){
sum += stones[i];
}
bool dp[n+1][sum+1];
for(int i=0; i<n+1; i++){
for(int j=0; j<sum+1; j++){
if(i==0)
dp[i][j]=false;
if(j==0)
dp[i][j]=true;
}
}
for(int i=1; i<n+1; i++){
for(int j=1; j<sum+1; j++){
if(stones[i-1]<=j){
dp[i][j]=dp[i-1][j]+dp[i-1][j-stones[i-1]];
}
else
dp[i][j]=dp[i-1][j];
}
}
vector<int> temp;
for(int j=0; j<=(sum/2); j++){
if(dp[n][j]==true){
temp.push_back(j);
}
}
int max=-1;
for(int i=0; i<temp.size(); i++){
if(temp[i]>max)
max=temp[i];
}
int res = sum - (2*max);
return res;
}
int main()
{
int N;
cin >> N;
int c;
vector<int> powerstones;
for(int i =0; i < N ; i++){
cin >> c;
powerstones.push_back(c);
}
cout << laststonepower(powerstones) << endl ;
return 0;
}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?