Pagini recente » Cod sursa (job #292508) | Cod sursa (job #1540278) | Cod sursa (job #269831) | Cod sursa (job #2063843) | Cod sursa (job #1371850)
// subsecventa.cpp : Defines the entry point for the console application.
//
#include "iostream"
#include "algorithm"
#include "fstream"
using namespace std;
ifstream inputFile;
ofstream outFile;
void ssm(int n)
{
int newInt;
inputFile >> newInt;
int *best = new int[n];
int *maxCompute = new int[n];
best[0] = newInt;
maxCompute[0] = 0;
for (int i = 1; i < n; i++)
{
inputFile >> newInt;
if (newInt > best[i - 1] + newInt)
{
best[i] = newInt;
maxCompute[i] = 0;
}
else
{
best[i] = best[i - 1] + newInt;
maxCompute[i] = 1;
}
}
int max = best[0];
int end = 0;
int start = 0;
for (int i = 0; i < n; i++)
if (max < best[i])
{
end = i;
max = best[i];
}
outFile << max << " ";
start = end;
while (maxCompute[start])
{
start--;
}
outFile << start + 1 << " " << end + 1;
}
int main()
{
inputFile.open("ssm.in", ios::in);
outFile.open("ssm.out", ios::out);
int n;
inputFile >> n;
ssm(n);
inputFile.close();
outFile.close();
return 0;
}