| 
 | 
back to boardWhy i got WA?Can anybody tell me? Thanks! Here is my program var  n,k,i,time:longint;   begin  readln(n,k);  if k=1 then writeln(n-1)   else    begin     i:=0;time:=0;n:=n-1;     while n>0 do      begin       if i<k then i:=i+1;       n:=n-i;time:=time+1;      end;     writeln(time);    end; end. Re: Why i got WA?Can anybody tell me? Thanks! > Here is my program > var >  n,k,i,time:longint; > > begin >  readln(n,k); >  if k=1 then writeln(n-1) >   else >    begin >     i:=0;time:=0;n:=n-1; >     while n>0 do >      begin >(***)  if i<k then i:=i+1; >       n:=n-i;time:=time+1; >      end; >     writeln(time); >    end; > end.   Have a look at the iteraton..as I understand i is the number of used cables... But on each iteration you should not add only one cable (***) but as much as possible, I mean if you have used i cables by now, next time you could use 2*i cables, if you have so much, NOT i:=i+1! Sample input: 12 6 Sample output: 4   1 sec.   1-2 2 sec.   1-3, 2-4 3 sec.   1-5,2-6,3-7,4-8 4 sec.   1-9,2-10,3-11,4-12 Bye! and Have a luck :) Re: Why i got WA?Can anybody tell me? Thanks! thanks ...!!!  |  
  | 
|