Pagini recente » Arhiva de probleme | Cod sursa (job #2023994) | Cod sursa (job #1154544) | Cod sursa (job #997056) | Cod sursa (job #1788052)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,a,k;
FILE * fp;
fp = fopen("secv2.in","r");
fscanf(fp,"%i",&n);
fscanf(fp,"%i",&k);
int left = 0;
int maxright = 0;
int maxleft = 0;
int sc = 0;
int scmax = -100000;
for(i = 0;i<n;i++)
{
fscanf(fp,"%i",&a);
if(sc < 0)
{
sc = 0;
left = i;
}
sc+=a;
if(sc > scmax && i - left >= k)
{
scmax = sc;
maxright = i;
maxleft = left;
}
}
fclose(fp);
fp = fopen("secv2.out","w");
fprintf(fp,"%i %i %i",maxleft+1,maxright+1,scmax);
fclose(fp);
return 0;
}