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

Why i get WA on test 5 ???
Posted by Лифанов 6 Mar 2005 10:56
#include  <stdio.h>

int main(){
    int mas[100000],i;
    for(i=0;i<100000;i++)
        mas[i]=0;
    int N,k;
    scanf("%ld",&N);
    for(i=0;i<N;i++){
        scanf("%ld",&k);
        mas[32768+k]=1;
    }
    scanf("%ld",&N);
    int sol=0,y;
    for(i=0;i<N;i++){
        scanf("%ld",&k);
        y=10000-k;
        if((y>=-32768)&&(y<=32767))
        if(mas[32768+y]==1){
            sol=1;
        }
    }
    if(sol)
        printf("YES");
    else
        printf("NO");

    return 0;
}
Re: Why i get WA on test 5 ???I get AC.
Posted by Лифанов 6 Mar 2005 11:34
I don't stand why my first solution wrong.
This programm get AC.
#include  <stdio.h>

int main(){
    int mas[100000],i;
    for(i=0;i<100000;i++)
        mas[i]=0;
    int N,k,y;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&k);
        y=32768+k;
        mas[y]=1;
    }
    scanf("%d",&N);
    int sol=0;
    for(i=0;i<N;i++){
        scanf("%d",&k);
        y=10000-k;
        if((y>=-32768)&&(y<=32767)){
            y=32768+y;
            if(mas[y]==1){
                sol=1;
                break;
            }
        }
    }
    if(sol)
        printf("YES");
    else
        printf("NO");

    return 0;
}