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 1787. Turn for MEGA

WA10?
Posted by Dashka_Bu 23 Feb 2012 21:12
I can not understand, why my program does not run on 10th test. Please help me!
program mega;
var a:array [1..100] of integer;
k,n,i:integer;
begin
 read(k, n);
 for i:=1 to n do
  read(a[i]);
 for i:=1 to n do
  if a[i]-k>0 then a[i+1]:=a[i+1]+(a[i]-k);
if a[n]-k> 0 then writeln(a[n]-k)
else write ('0');
end.
Re: WA10?
Posted by Angel 25 Feb 2012 22:46
I have the same problem
#include "stdafx.h"
#include<stdio.h>
//#include<conio.h>
//#include<math.h>

void main()
{
    int k,n,A[100],i;
    scanf("%d %d", &k, &n);
    for (i=0; i<n; i++)
        scanf("%d", &A[i]);
    for (i=0; i<n; i++)
        if (A[i]>k)
                A[i+1]+=(A[i]-k);
    if (A[n-1]>k) printf("%d", A[n-1]-k);
    else printf("0");
    //getch();
}