Cod sursa(job #3285448)
Utilizator | Data | 12 martie 2025 21:17:41 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 95 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.61 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int n;
long long a[6000001];
int main()
{
f >> n;
for(int i = 1; i <= n; ++i) {
f >> a[i];
}
long long smax = a[0], s = a[0];
int st = 1, dr = 1, temp = 1;
for(int i = 1; i <= n; ++i) {
if(s + a[i] < a[i]) {
s = a[i];
temp = i;
}
else{
s += a[i];
}
if(s > smax){
smax = s;
st = temp;
dr = i;
}
}
g << smax << " " << st << " " << dr;
}