Pagini recente » Cod sursa (job #1886859) | Cod sursa (job #2501616) | Cod sursa (job #1637173) | Cod sursa (job #2716065) | Cod sursa (job #2892861)
#include <iostream>
using namespace std;
int n;
int main()
{
freopen("ssm.in", "r", stdin);
freopen("ssm.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int v;
int dp1, dp2, len, index;
int dp_max, len_max, index_max;
cin >> n;
cin >> v;
dp1 = v, dp_max = 1;
len = 1, len_max = len;
index_max = 1;
for (int i = 2; i <= n; i++)
{
cin >> v;
dp2 = max(dp1 + v, v);
if (dp1 + v >= v) {
len++;
}
else {
len = 1;
}
dp1 = dp2;
if (dp1 > dp_max) {
dp_max = dp1;
len_max = len;
index_max = i;
}
else if (dp1 == dp_max) {
if (len_max < len) {
len_max = len;
index_max = i;
}
}
}
cout << dp_max << " " << index_max - len_max + 1 << " " << index_max;
return 0;
}