In this HackerEarth Charged Up Array problem solution, You are given an array A of size N. An element Ai is said to be charged if its value(Ai) is greater than or equal to Ki. Ki is the total number of subsets of array A, that consist of element Ai. 
The total charge value of the array is defined as the summation of all charged elements present in the array mod (10 to power 9 plus 7). Your task is to output the total charge value of the given array A.


HackerEarth Charged Up Array problem solution


HackerEarth Charged Up Array problem solution.

#include <bits/stdc++.h>
#define M 1000000007
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T;
    cin>>T;
    while(T--)
    {
        int N;
        cin>>N;
        long long arr[N];
        for(int i=0;i<N;i++)
            cin>>arr[i];
        if(N>=64)
            cout<<0<<endl;
        else
        {
            long long val=(1ll<<(N-1));
            long long ans=0;
            for(int i=0;i<N;i++)
                if(arr[i]>=val)
                    ans=(ans+arr[i]%M)%M;
            cout<<ans<<endl;
        }
    }
}