Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <cstring>
- #include <fstream>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<long long> sum_left(19, 0), sum_right(19, 0);
- for(int i = 1; i <= n; i++) {
- int broj;
- cin >> broj;
- int p = n / 2;
- int t = 0;
- while(p >= 1) {
- if(i <= p) {
- sum_left[t] += broj;
- }
- else {
- sum_right[t] += broj;
- }
- t++;
- p /= 2;
- }
- }
- long long sum = 0;
- for(int i = 0; i < log2(n); i++) {
- sum_right[i] -= sum;
- sum += sum_right[i];
- }
- long long result = 0;
- for(int i = 0; i < log2(n); i++) {
- result += sum_left[i] - sum_right[i];
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement