main.cpp (1084B)
1 #include <iostream> 2 #include <vector> 3 #include <unordered_set> 4 #include <unordered_map> 5 #include <algorithm> 6 #include <queue> 7 8 #define ll long long 9 10 using namespace std; 11 12 // n integers 13 // a_1... rep position 14 // start at 0 15 16 // choose p 17 // token is reflected over 18 // p, a_1, ... a_n 19 20 // end at 0 21 22 // 1 23 // 3 24 25 // 0 -> 6 26 // 0 -> 6 -> 0 27 28 // this is done with p == 3 29 30 // 2 31 // 2 5 32 33 // 0 -> 4 -> 6 34 35 // 0 -> 12 -> -4 -> ... 36 37 38 // prior to last step, must be at 10 39 // to get to 10 from 2 we must be at -6 40 // to get to -6 from 0 we must have -3 41 // so we have -3 42 43 // 3 44 // 2 7 1 45 // 4 46 // -3 0 -3 0 47 // 1 48 // 0 49 50 51 int main() { 52 int testCases, current, n; 53 cin >> testCases; 54 55 for(int z = 0; z < testCases; ++z) { 56 57 cin >> n; 58 vector<int> ls {}; 59 60 for(int i = 0; i < n; ++i) { 61 cin >> current; 62 ls.push_back(current); 63 } 64 65 int target = 0; 66 67 for(int i = ls.size()-1; i >= 0; --i) { 68 int pivot = ls[i]; 69 target = ((pivot - target) * 2) + target; 70 } 71 cout << target / 2 << endl; 72 } 73 }