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 1196. History Exam

please tell me why i have acces violation on test #8?
Posted by Husan 24 Jan 2007 15:47
#include<iostream.h>
#include<fstream.h>
int main()
{
long teach[25005],stud[200005];
long i,j,kol=0,k,l,r,n,m;
cin>>n;
for(i=1;i<=n;i++)cin>>teach[i];
cin>>m;
for(i=1;i<=m;i++)
{
    cin>>stud[i];
    l=1;r=n;
    for(j=1;j<=m;j++)
    {
    if(stud[i]<teach[1])break;else
    {
    k=(l+r)/2;
    if(stud[i]>teach[k])l=k+1;else
    if(stud[i]<teach[k])r=k-1;else {kol++;break;}
    }
    }
}cout<<kol;
return 0;
}
Re: please tell me why i have acces violation on test #8?
Posted by KIRILL(ArcSTU) 24 Jan 2007 18:37
M <=1000000, but

for(j=1;j<=m;j++)
{
if(stud[i]<teach[1])break;else
{
k=(l+r)/2;
if(stud[i]>teach[k])l=k+1;else
if(stud[i]<teach[k])r=k-1;else {kol++;break;}
}
}
It's not correct

You should not to store student years
Just read next student year and find it
with binary search in teach[]