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

Please help!!!!
Posted by 902 group (RAU) 10 Nov 2009 21:34
Please help!!!Tell me what is wrong in my algo???Help to orgonise input!Here is my code:
#include <iostream.h>
int main()
{
    const int N=50000;
    int x[N],y[N];
    bool s;
    int i,k;
    int a,b;
    cin>>a;
    for(i=0;i<a;i++)
    {
        cin>>x[i];
    }
    cin>>b;
    for(i=0;i<b;i++)
    {
        cin>>y[i];
    }
    for(i=0;i<a;i++)
    {
        for(k=0;k<b;k++)
        {
            if(x[i]+y[k]==10000)
            {
                s=true;
            }
            if(x[i]+y[i]!=10000)
            {
                s=false;
            }
        }
    }
    if(s=true)
    {
        cout<<"YES"<<endl;
    }
    if(s=false)
    {
        cout<<"NO"<<endl;
    }
    return 0;

}
Re: Please help!!!!
Posted by melkiy 10 Nov 2009 21:53
You must finish your iterations and print "YES", if an appropriate pair of numbers is found.
Now your program outputs the value of the 's' for the last pair, x[a-1] and y[b-1].

But this algo can be substantially optimized.