Cod sursa(job #2478048)

Utilizator Victor2006Nicola Victor-Teodor Victor2006 Data 21 octombrie 2019 16:21:06
Problema Secventa 2 Scor 100
Compilator c-64 Status done
Runda Arhiva de probleme Marime 2.28 kb








#include <stdio.h>































#define N 50000































#define INF 1500000































































int s[N + 1];































int a[N + 1];































































int oof( int a, int b ) {































  if ( a > b )































    return a;































  return b;































}































































int main() {































  FILE *fin, *fout;































  int n, k, i, sc, smax, stmax, drmax, stc;































  fin = fopen( "secv2.in", "r" );































  fscanf( fin, "%d%d", &n, &k );































  for ( i = 1; i <= n; i ++ ) {































    fscanf( fin, "%d", &a[i] );































    s[i] = s[i - 1] + a[i];































  }































  sc = smax = s[k];































  stc = stmax = 1;































  drmax = k;































  for ( i = k + 1; i <= n; i ++ ) {































    fscanf( fin, "%d", &a[i] );































    s[i] = s[i - 1] + a[i];































    if ( s[i] - s[i - k] > sc + a[i] ) {































      sc = s[i] - s[i - k];































      stc = i - k + 1;































    } else {































      sc += a[i];































    }































    if ( sc > smax ) {































        smax = sc;































        stmax = stc;































        drmax = i;































    }































  }































  fclose( fin );































































  fout = fopen( "secv2.out", "w" );































  fprintf( fout, "%d %d %d\n", stmax, drmax, smax );































  fclose( fout );































  return 0;































}