-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxSLiceSum.cpp
More file actions
35 lines (28 loc) · 834 Bytes
/
MaxSLiceSum.cpp
File metadata and controls
35 lines (28 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// you can use includes, for example:
#include <algorithm>
#include <math.h>
#include <iostream>
#include <limits.h>
#include <numeric>
#include <climits>
#include <stdlib.h>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A) {
// write your code in C++14 (g++ 6.2.0)
int maxdoubleslice = std::accumulate((A.begin()), (A.end()), 0);
int xy;
for(int x = 0;x < A.size();x++)
{
for(int y = x+1;y < A.size();y++)
{
xy = std::accumulate((A.begin() + (x)), (A.begin() + y), 0);
//cout << "x " << x << " y " << y<< " xy "<< xy << endl;
if(xy > maxdoubleslice)
{
maxdoubleslice = xy;
}
}
}
return maxdoubleslice;
}