Cod sursa(job #2869088)
Utilizator | Vlad Andrei vladxandrew | Data | 11 martie 2022 12:27:31 |
---|---|---|---|
Problema | Secventa 2 | Scor | 50 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("secv2.in");
ofstream g("secv2.out");
int n, k, a[50001], smax, pi, pf;
int main()
{
f >> n >> k;
for (int i = 1; i <= n; ++i)
f >> a[i];
for (int i = 1; i <= n; ++i)
{
long long s(0), z(0);
for (int j = i; j <= n; ++j)
{
s += a[j];
z++;
if (s > smax && z >= k)
{
smax = s;
pi = i;
pf = j;
}
}
}
g << pi << " " << pf << " " << smax;
}