Pagini recente » Cod sursa (job #3030652) | Cod sursa (job #2694264) | Cod sursa (job #3230279) | Cod sursa (job #2112674) | Cod sursa (job #612702)
Cod sursa(job #612702)
//Subsecventa de suma maxima - infoarena.ro
#include "fstream"
using namespace std;
int main()
{
int max_here = 0, max_total = 0, temp, c1, c2, c1_temp = 0;
ifstream in("ssm.in");
int n;
in >> n;
for (int i = 0; i < n; ++i)
{
in >> temp;
if (max_here < 0)
{
max_here = temp;
c1_temp = i;
}
else
max_here += temp;
if (max_here > max_total)
{
max_total = max_here;
c1 = c1_temp;
c2 = i;
}
}
in.close();
ofstream out("ssm.out");
out << max_total << " " << c1+1 << " " << c2+1 << " " << endl;
out.close();
return 0;
}