Pagini recente » Cod sursa (job #2881272) | Cod sursa (job #3125622) | Cod sursa (job #1311868) | Cod sursa (job #2211891) | Cod sursa (job #672306)
Cod sursa(job #672306)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n, v[6000005], best[6000005], lung[6000005];
void citire() {
int i;
f>>n;
for(i=1; i<=n; i++) f>>v[i];
}
void rezolva() {
int i;
best[1]=v[1];
lung[1]=1;
for(i=2; i<=n; i++) {
if(best[i-1]>0) { best[i]=best[i-1]+v[i]; }
else { best[i]=v[i]; }
}
int max=0, lungmax=0;
//secventa se termina unde ii maximu, incepe unde ii primul best negativ dinainte maximului
for(i=1; i<=n; i++) if(best[i]>max) max=best[i];
i=n;
int start, stop;
while(i>=1) {
if(best[i]==max) {
stop=i;
break;
}
i--;
}
i=stop;
while(i>=1) {
i--;
if(best[i]<=0) { start=i+1; break; }
}
g<<max<<" "<<start<<" "<<stop<<"\n";
// for(i=1; i<=n; i++) g<<best[i]<<" "; g<<"\n";
}
int main() {
citire();
rezolva();
f.close();
g.close();
return 0;
}