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

AC O(2n)
Posted by huzujun 24 Jan 2013 09:49
#include<iostream>
#include<cmath>

using namespace std;

int a1[100000],a2[100000];
int main()
{
    int n1,n2;
    cin>>n1;
    for (int i=1; i<=n1; i++) cin>>a1[i];
    cin>>n2;
    for (int i=1; i<=n2; i++) cin>>a2[i];
    int i=1,j=1;
    bool bk=false;
    while (i<=n1 || j<=n2)
    {
        if (a1[i]+a2[j]==10000)
        {
            bk=true;
            break;
        }
        if (a1[i]+a2[j]<10000)
          if (i==n1) break; else i++;
        else
          if (j==n2) break; else j++;
    }
    if (bk==false) cout<<"NO"<<endl;
       else cout<<"YES"<<endl;
    return 0;
}