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 WA test 5
Posted by Samvel Petrosov 29 Nov 2009 10:28
here is my algo
#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
const int N=50000;
int a[N],b[N],i,n,k,c[N],d[N],s=0;
bool p=true;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
cin>>k;
int j=k-1;
for(i=0;i<k;i++)
cin>>b[i];
int x=0,y=0;
for(i=0;i<n;i++)
    c[x++]=a[i];
for(i=0;i<k;i++)
    d[y++]=b[i];
nth_element(c,c,c+n);
nth_element(d,d,d+k);
for(i=n-1;i>=0;i--)
{
    while(j>=0)
    {
        s=d[j]+c[i];
        j--;
        if(s==10000)
        {
        p=true;
        break;
        }
        else
            p=false;
    }
    if(p==true)
        break;

}
if(p==true)
{
    cout<<"YES"<<endl;
}
else
cout<<"NO"<<endl;
return 0;
}
Re: Why WA test 5
Posted by tiancaihb 2 Dec 2009 16:02
Ununderstandable
Re: Why WA test 4
Posted by mirzauzairbaig 13 Jan 2010 05:29
// code removed !
issue resolved !!

Edited by author 13.01.2010 20:25
Re: Why WA test 4
Posted by Atbasar(GBK) 20 Jan 2010 22:14
use Quick sort:
int Partition(int low,int high,int a[])
{
    int high_vac,low_vac,pivot;
    pivot=a[low];
    while(high>low)
    {
        high_vac=a[high];
        while(pivot<high_vac)
        {
            if(high<=low)break;
            high--;
            high_vac=a[high];
        }
        a[low]=high_vac;
        low_vac=a[low];
        while(pivot>low_vac)
        {
            if(high<=low)break;
            low++;
            low_vac=a[low];
        }
        a[high]=low_vac;
    }
    a[low]=pivot;
    return low;
}
void Quicksort(int low,int high,int a[])
{
    int Piv_index;
    if(low<high)
    {
        Piv_index=Partition(low,high,a);
        Quicksort(low,Piv_index-1,a);
        Quicksort(Piv_index+1,high,a);
    }
}
then binary_search
Samo es el kez quicksort

Edited by author 28.01.2010 21:14
Re: Why WA test 4
Posted by RAU(1 course) 28 Jan 2010 21:23
Samo es test@ stugi:
3
0 0 10000
3
10000 10000 0