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 1190. Bar of Chocolate

Please help me with this problem... test my program..
Posted by Reshetnikov Eugeny 8 Mar 2002 23:28
This is my program! Please give me some tests and said what my
program must write, and why... Please help!

Program n1190;
  Var n,sum,x,count,i,min:longint;
      code               :integer;
      s                  :string[255];

Procedure Input_Solve;
  Begin
    ReadLn(n);
    min:=0; count:=0; sum:=0;
    While n>0 Do Begin
      n:=n-1;
      ReadLn(s);
      Delete(s,1,Pos(' ',s));
      If Copy(s,1,1)='0' Then count:=count+1
      Else Begin
        Delete(s,1,2);
        Val(s,x,code);
        If min=0 Then min:=x Else
        If min>x Then min:=x Else
        If x>min Then sum:=10001;
        sum:=sum+(count+1)*x;
        count:=0;
      End;
    End;
    If (count>0) and (sum<10000) and (count*min+sum>=10000) Then
      sum:=10000;
    If (count>0) and (min=0) Then
      sum:=10000;
  End;

Procedure Write_It;
  Begin
    If sum<>10000 Then WriteLn('NO') Else WriteLn('YES');
  End;

Begin
  Input_Solve;
  Write_It;
End.
It's easy(+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 10 Mar 2002 13:48
5
a1 1 2001
a2 0
a3 0
a4 0
a5 1 1999

Rigth answer - YES
Really,
a1 = 2001
a2 = 2000
a3 = 2000
a4 = 2000
a5 = 1999

a1+a2+a3+a4+a5=10000

Why?
See:

min(a1+a2+a3+a4+a5)=2001+1999+1999+1999+1999=9997
max(a1+a2+a3+a4+a5)=2001+2001+2001+2001+1999=10003

As min(a1+a2+a3+a4+a5)<=10000<=max(a1+a2+a3+a4+a5) we must write "YES"