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 1005. Stone Pile

help me test 5
Posted by Igor 14 Sep 2005 23:45
#include <iostream>
using namespace std;


long long a,n,w[25],c,s,b;
int main()
{
   cin >>n;
   a=1;  w[0]=0;
   for ( ;a<=n;a++)
      cin >>w[a];
   a=1;
   if (n==1) cout <<w[1]<<"\n"; else
   {
     for ( ;a<=n;a++)
     {
         s=a;
         for ( s;s<=n-1;s++)
           {
             if (w[a]>w[s+1]) { c=w[a]; w[a]=w[s+1]; w[s+1]=c;};
           }
     }
     a=n;
     for ( ;a>=3;a--)
       {
         w[a-1]=w[a]-w[a-1];
         if (w[a-2]>w[a-1]) {c=w[a-2]; w[a-2]=w[a-1]; w[a-1]=c;};
       }
     cout <<w[2]-w[1]<<"\n";
   }

   return 0;
}
Re: help me test 5
Posted by hardfire 9 Mar 2007 18:53
You solve is very big.
My solve get WA5, but my solve if less.
on C:
#include <stdio.h>
void main()
{
int n,i,j;
__int64 w[21],s1=0,s2=0;
scanf("%d",&n);
for(i=0;i<n;++i)scanf("%I64d",&w[i]);
for(i=0;i<n-1;++i)for(j=i+1;j<n;++j)
  if(w[i]<w[j]){int t=w[i];w[i]=w[j]; w[j]=t;};
s1=w[0];
for(i=1;i<n;++i)
  if(s1<s2)s1+=w[i];
  else s2+=w[i];
if(s1>s2)s1-=s2;
else s1=s2-s1;
printf("%I64d",s1);
}
Re: help me test 5
Posted by Romko [Lviv NU] 9 Mar 2007 19:28
Both solution is wrang. Try full search.