Advertisement
Josif_tepe

Untitled

Mar 6th, 2022
920
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <cstring>
  7. #include <fstream>
  8. using namespace std;
  9. int main() {
  10.    
  11.     int n;
  12.     cin >> n;
  13.    
  14.     vector<long long> sum_left(19, 0), sum_right(19, 0);
  15.     for(int i = 1; i <= n; i++) {
  16.         int broj;
  17.         cin >> broj;
  18.         int p = n / 2;
  19.         int t = 0;
  20.         while(p >= 1) {
  21.             if(i <= p) {
  22.                 sum_left[t] += broj;
  23.             }
  24.             else {
  25.                 sum_right[t] += broj;
  26.             }
  27.             t++;
  28.             p /= 2;
  29.         }
  30.     }
  31.     long long sum = 0;
  32.     for(int i = 0; i < log2(n); i++) {
  33.         sum_right[i] -= sum;
  34.         sum += sum_right[i];
  35.     }
  36.     long long result = 0;
  37.     for(int i = 0; i < log2(n); i++) {
  38.         result += sum_left[i] - sum_right[i];
  39.     }
  40.     cout << result << endl;
  41.    
  42.     return 0;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement