ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1061. Buffer Manager

Why I got WA ?
Posted by Alexandru Popa 2 May 2003 13:26
#include <stdio.h>

long n, z, s, poz, min = 10000000;
int k;
char sir[100009];
//FILE *f;

int main ()
{
    long i, j;

    //f = fopen("buffer.in","r");
    scanf("%ld %d",&n,&k);
    if((long)k > n) printf("0\n");
    else {
         scanf("%c",&sir[0]);
         for(i=1; i<=n; i++)
        {
        scanf("%c",&sir[i]);
        if(sir[i] == '\n')
          i--;
        }
         for(i=1; i<=k; i++)
        {
        z--;
        if(sir[i] == '*')
          {
          s += 10;
          z = k;
          }
        else s += sir[i] - '0';
        }
        if(z <= 0 && s < min)
          {
          min = s;
          poz = i-k;
          }
         for(; i<=n; i++)
        {
        if(sir[i-k] == '*')
          s -= 10;
        else s -= sir[i-k] - '0';
        z--;
        if(sir[i] == '*')
          {
          s += 10;
          z = k;
          }
        else s += sir[i] - '0';
        if(z <= 0 && s < min)
          {
          min = s;
          poz = i-k+1;
          }
        }
         }
    printf("%ld\n",poz);
    return 0;
}