A non-empty zero-indexed array A consisting of N integers is given. A pair of integers (P, Q), such that 0 ≤ P ≤ Q < N, is called a slice of array A. The sum of a slice (P, Q) is the total of A[P] + A[P+1] + ... + A[Q].
Write a function:
int solution(const vector<int> &A);
that, given an array A consisting of N integers, returns the maximum sum of any slice of A.
// you can use includes, for example:
#include
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(const vector
&A) {
// write your code in C++11
if(A.empty())
return 0;
int max_ending = A[0];
int max_slice = A[0];
for(unsigned int i=1;i
MaxDoubleSlice:
Task description
A non-empty zero-indexed array A consisting of N integers is given.
A triplet (X, Y, Z), such that 0 ≤ X < Y < Z < N, is called a double slice.
The sum of double slice (X, Y, Z) is the total of A[X + 1] + A[X + 2] + ... + A[Y − 1] + A[Y + 1] + A[Y + 2] + ... + A[Z − 1].
// you can use includes, for example:
#include
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
inline int max(int a,int b,int c)
{
if(a
&A) {
// write your code in C++11
if(A.size()<4)
return 0;
//右边界为i时两段最大值max_ending
//中间点为i时左子列最大部分和max_left
//整个数组最大部分和max_slice
int max_ending = 0 , max_left = 0 , max_slice = 0;
for(unsigned int i=3;i
Task descriptionA non-empty zero-indexed array A consisting of N integers is given.A triplet (X, Y, Z), such that 0 ≤ X double slice.The sum of double slice (X, Y, Z) is the total of A[X + 1