Mai intai trebuie sa te autentifici.
Cod sursa(job #3157173)
Utilizator | Data | 14 octombrie 2023 15:55:37 | |
---|---|---|---|
Problema | Secventa 2 | Scor | 80 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.67 kb |
#include <fstream>
using namespace std;
ifstream cin("secv2.in");
ofstream cout("secv2.out");
int sum_part[50001];
int main()
{
int n, i, k, x, poz, pozmin, pozmax, xmin = 99999, xmax;
cin >> n >> k;
for(i = 1; i <= n; i ++){
cin >> x;
sum_part[i] = sum_part[i - 1] + x;
}
for(i = k; i <= n; i ++){
if(sum_part[i - k] < xmin){
xmin = sum_part[i - k];
poz = i - k + 1;
}
if(sum_part[i] - xmin > xmax){
pozmin = poz;
pozmax = i;
xmax = sum_part[i] - xmin;
}
}
cout << pozmin << " " << pozmax << " " << xmax;
return 0;
}