1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <bitset>
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int x, y;
    std::cin >> x >> y;

    std::vector<int> numbers(x);
    std::vector<unsigned int> bits(x);

    for(int i =0; i < x; i++)
    {
        std::cin >> numbers[i];
    }

    for(int i = x - 1; i >= 0; i--)
    {
        bits[i] = (y - (x - i) + 1) >= 0 ? y - (x - i) + 1 : 0;
    }

    int acc = 0;

    for(int i = 0; i < x; i++)
    {
        acc += numbers[i] * std::bitset<32>{bits[i]}.count();
    }

    std::cout << acc << std::endl;
    return 0;
}