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 1021. Sacrament of the Sum

What's wrong
Posted by Marek Kiszkis 8 Oct 2002 21:16
Help me PLEASE!
What's wrong with it?
I always get WA.

program timus_1021;
var
 t1, t2:array [1..50000] of longint;
 j, i, l1, l2, l:longint;
 wyn:boolean;
begin
 readln (l1);
 for i:=1 to l1 do
  readln (t1[i]);
 readln (l2);
 for i:=1 to l2 do
  readln (t2[i]);
 i:=0;
 wyn:=false;
 repeat
  inc (i);
  j:=l2;
  while t1[i]+t2[j]<10000 do
   dec (j);
  if t1[i]+t2[j]=10000 then wyn:=true;
 until i=l1;
 if wyn then writeln ('YES')
  else writeln ('NO')
end.
Re: What's wrong
Posted by Sashko 14 Mar 2003 20:33
> Help me PLEASE!
> What's wrong with it?
> I always get WA.

>   while t1[i]+t2[j]<10000 do
>    dec (j);
>   if t1[i]+t2[j]=10000 then wyn:=true;
...

  Did you sort the sequence ? No You didn't, So why do You expect
that after
  "t1[i]+t2[j]<10000"
can't be
  "t1[i]+t2[j]>10000"
and then
  "t1[i]+t2[j]<10000" again ?

You must either sort the arrays before, or change the condition
in "while", to check ALL combinations.
Re: what is my problem in here you can give tests
Posted by zzzlll 3 Jan 2007 17:09

var
say,say2:array [1..10000] of integer;
n,k,i,m,s:longint;
begin
 s:=0;
 readln(n);
    repeat
    k:=k+1;
    readln(say[k]);
    until k=n;
 readln(m);
    repeat
    i:=i+1;
    readln(say2[i]);
    until i=m;
 i:=0;
 k:=0;
    repeat
    k:=k+1;
       repeat
       i:=i+1;
       if (say[k]+say2[i])=10000  then s:=1;
       until s=1;
    until s=1;
  if s=1  then writeln('yes')
  else writeln('no');
 end.