Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- long long FindMax(int size, long long **A)
- {
- long long max = 0;
- for (int j = 0; j < size; ++j)
- {
- if (A[0][size - 1] + A[1][j] > max)
- {
- max = A[0][size - 1] + A[1][j];
- }
- else
- if (A[0][size - 1] - A[2][j] > max)
- {
- max = A[0][size - 1] - A[2][j];
- }
- }
- return max;
- }
- void SetTables(int j, long long **A)
- {
- if (j != 0)
- {
- if (A[1][j - 1] > 0)
- {
- A[1][j] = A[1][j - 1] + A[0][j];
- }
- else
- {
- A[1][j] = A[0][j];
- }
- if (A[2][j - 1] < 0)
- {
- A[2][j] = A[2][j - 1] + A[0][j];
- }
- else
- {
- A[2][j] = A[0][j];
- }
- A[0][j] += A[0][j - 1];
- }
- else
- if (j == 0)
- {
- A[1][j] = A[0][j];
- A[2][j] = A[0][j];
- }
- }
- int main()
- {
- //std::ios_base::sync_with_stdio(0);
- //std::cin.tie(nullptr);
- //std::cout.tie(nullptr);
- long long n, m, max = 0;
- std::cin >> n;
- for (int i = 0; i < n; ++i)
- {
- std::cin >> m;
- long long ** T = new long long * [3];
- T[0] = new long long[m];
- T[1] = new long long[m];
- T[2] = new long long[m];
- for (int j = 0; j < m - 1; ++j)
- {
- std::cin >> T[0][j];
- SetTables(j, T);
- }
- std::cout << FindMax(m - 1, T) << "\n";
- delete [] T[0], T[1], T[2], T;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement