You are given an array A of size N An element A i is said to be charged if its value(
) is greater than or equal to . is the total number of subsets of array , that consist of element .
Total charge value of the array is defined as the summation of all charged elements present in the array mod .
Your task is to output the total charge value of the given array .
Example:
Input: n = 3, a = [3,4,5]
Output: 9
Approach
C++
#include <bits/stdc++.h>using namespace std;#define MOD 1000000007long long chargeArray(long long n, long long a[]){long long ans = 0;for (long long i = 0; i < n; i++){if (a[i] >= pow(2, n) / 2){ans = (ans + a[i]) % MOD;}}return ans % MOD;}int main(){long long n = 3;long long a[n] = {3, 4, 5};cout << chargeArray(n, a) << "\n";return 0;}
No comments:
Post a Comment