Pagini recente » Cod sursa (job #878363) | Cod sursa (job #2551005) | Cod sursa (job #2176100) | Cod sursa (job #2711696) | Cod sursa (job #612701)
Cod sursa(job #612701)
//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 << " " << c2 << " " << endl;
out.close();
return 0;
}