Pagini recente » Cod sursa (job #1695599) | Cod sursa (job #2585295) | Cod sursa (job #1090636) | Cod sursa (job #1555347) | Cod sursa (job #612703)
Cod sursa(job #612703)
//Subsecventa de suma maxima - infoarena.ro
#include "fstream"
using namespace std;
int main()
{
int max_here = 0, max_total = -int(2e9), 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;
}