Pagini recente » Profil commercialgas511 | Cod sursa (job #408249) | Cod sursa (job #161906) | Istoria paginii runda/ason | Cod sursa (job #1829469)
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream f("ssm.in");
ofstream g("ssm.out");
int n, i;
int max_ending_here = 0;
int max_so_far = 0;
int max_starting_at = 0;
int current_max_pos = 0;
int max_ends_at = 0;
int v[6000000];
f >> n;
for(i=1;i<=n;i++)
f >> v[i];
for (int a = 0; a < n; a++) {
int x = v[a];
max_ending_here = max(0, max_ending_here + x);
if (max_so_far > max_ending_here){
max_starting_at = current_max_pos;
max_ends_at = a;
}
max_so_far = max(max_so_far, max_ending_here);
if (max_ending_here == 0){
current_max_pos = a;
}
}
g << max_so_far << ", " << current_max_pos + 1 << ", " << max_ends_at + 1;
f.close();
g.close();
return 0;
}