Pagini recente » Cod sursa (job #964162) | Cod sursa (job #1577122) | Cod sursa (job #847776) | Cod sursa (job #1113967) | Cod sursa (job #1796525)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
void citesteSir(long x[],long long& n){
ifstream is("ssm.in");
is>>n;
for (int i=0;i<n;i++){
is>>x[i];
}
is.close();
}
void scrieSir(long x[],long long n,long st,long dr){
ofstream os("ssm.out");
for (int i =st;i<dr;i++){
os<<x[i]<<" ";
}
os.close();
}
int calculeazaSecvSumaMaxima(long x[],long long n,long& st,long& dr){
long best= x[0];
long bbest =best;
long bst,bdr;
st=dr=bst=bdr=0;
for (int i=1;i<n;i++){
if (best+x[i]>=x[i]){
dr++;
best +=x[i];
}else{
st=dr=i;
best = x[i];
}
if (best>bbest){
bbest = best;
bst = st;
bdr = dr;
}
}
st = bst+1;
dr = bdr+1;
return bbest;
}
int main(){
long long n;
long x[100];
citesteSir(x,n);
long st,dr;
long best = calculeazaSecvSumaMaxima(x,n,st,dr);
ofstream os("ssm.out");
os<<best<<" "<<st<<" "<<dr;
os.close();
}