ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1021. Sacrament of the Sum

Pomogite TLE na 10 teste ; Help TLE on 10 th test
Posted by Hamdam_TUIT 28 Jun 2013 10:37
#include<iostream>
using namespace std;

short a[50001],b[50001];
int N,M,index_1_0,index_1_10,index_2_0,index_2_10;
bool f_0,f_10,t_0,t_10;
const int T=10000;

int main()
{
cin>>N;
for(int i=0;i<N;i++)
{
cin>>a[i];
if(a[i]>=0&&!f_0)
{
index_1_0=i;
f_0=true;
}
if(a[i]>=1000&&!f_10)
{
index_1_10=i;
f_10=true;
}
}
cin>>M;
for(int i=0;i<M;i++)
{
cin>>b[i];
if(b[i]<=0&&!t_0)
{
index_2_0=i;
t_0=true;
}
if(b[i]<=1000&&!t_10)
{
index_2_10=i;
f_10=true;
}
}
for(int i=0;i<=index_1_0;i++)
{
for(int j=0;j<=index_2_10;j++)
{
if(a[i]+b[j]<1000)
break;
if(a[i]+b[j]==T)
{
cout<<"YES";
return 0;
}
}
}
for(int i=index_1_0;i<=index_1_10;i++)
{
for(int j=index_2_10;j<=index_2_0;j++)
{
if(a[i]+b[j]<1000)
break;
if(a[i]+b[j]==T)
{
cout<<"YES";
return 0;
}
}
}
for(int i=index_1_10;i<N;i++)
{
for(int j=index_2_0;j<M;j++)
{
if(a[i]+b[j]<1000)
break;
if(a[i]+b[j]==T)
{
cout<<"YES";
return 0;
}
}
}
cout<<"NO";
}

Edited by author 28.06.2013 11:46