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!!why WA#5,who know test 5.
Posted by George Skhirtladze 12 Apr 2010 16:31
var a:array[0..10000]of integer;
    max,i,j,n,k,l,group1,group2:longint;
begin
 read(n);
 for i:=1 to n do
  read(a[i]);
 for i:=1 to n-1 do
  begin
   k:=i;
   max:=a[i];
   for j:=i+1 to n do
    if a[j]>max then
     begin
      max:=a[j];
      k:=j;
     end;
    a[k]:=a[i];
    a[i]:=max;
  end;
  for i:=3 to n do
  if group1<group2 then
   group1:=group1+a[i]
  else
   group2:=group2+a[i];
 writeln(abs(group1-group2));
end.
Re: Help me!!why WA#5,who know test 5.
Posted by ile 14 Apr 2010 03:28
this is wrong approach.

the right solution is DP or bruteforcing all combinations.
Re: Help me!!why WA#5,who know test 5.
Posted by nguyenductam 16 Apr 2010 13:58
Someone have function DP of this problem
Re: Help me!!why WA#5,who know test 5.
Posted by Alexander_UpRun(ONU) 19 Aug 2010 02:34
use BruteForce my program with it works good
difficulty of my algorithm is O(n* pow(2,20) = O(n*1048576)