Displaying the maximum sums of subsequences and its subsequence values

Hi I made this program expecting it to return the maximum sums of subsequences of the given integer array but also returns/outputs the actual subsequence where the sum of integers is maximum I also tried to create an array of specific size because I need to test it with different sizes like 1000, 10000, and to generate it randomly with positive and negative integers , I have tried to modify but I can't make it work, that but my knowledge is limited and I can't seem to find a way to fix it.

#include <iostream>
#include <vector>
#include <ctime>
#include <cstdlib>

using namespace std;

int* maxSubSum4(const vector<int>& a)
int maxSum = 0, thisSum = 0;
int from, till;
int n = a.size() + 1;
int result[n];
int* p = result;
for (int j = 0; j < a.size(); j++) {
thisSum += a[j];
if (thisSum > maxSum) {
maxSum = thisSum;
//from = i;
till = j;
else if (thisSum < 0)
thisSum = 0;
result[0] = maxSum;
int ind = 1;
for (int i = from; i <= till; i++) {
result[ind] = i;
return p;

int main() {
int size;
cout << "Enter size of the array: ";
cin >> size;
vector<int> vec;
int range = size/10;
for(int i = 0; i < size; ++i) {
vec.push_back(-range + (rand() % (2*range)));
int *arr = maxSubSum4(vec);
return 0;
return a std::vector from the function
for (int i = from; i <= till; i++) initialise `from'
Oh I commented that part in the code I don't remember why
Registered users can post here. Sign in or register to post.