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 1604. Country of Fools

help WA3
Posted by ACM.Krupko_Victor[Ivanovo SPU] 16 May 2008 03:04
program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
  var
     a,b:array[1..10001] of integer;
     t,i,n,t1,t2,j:longint;
begin
 { assign(input,'d:\input.txt'); reset(input);
   assign(output,'d:\output.txt'); rewrite(output);}
    readln(n);
    if n=1 then begin write(1); exit; end;
    for i:=1 to n do
        begin
           read(a[i]);
           b[i]:=i;
        end;
    for i:=1 to n-1 do
      for j:=i+1 to n do
      if a[i]<a[j] then
         begin
            a[i]:=a[i]+a[j];
            a[j]:=a[i]-a[j];
            a[i]:=a[i]-a[j];
            b[i]:=b[i]+b[j];
            b[j]:=b[i]-b[j];
            b[i]:=b[i]-b[j];
         end;
     t:=-1; a[n+1]:=-1;
     repeat
     if (t<>b[1]) and (a[1]<>0) then
       begin
        t:=b[1];
        a[1]:=a[1]-1;
       end
     else
     if (t<>b[2]) and (a[2]<>0) then
       begin
        t:=b[2];
        a[2]:=a[2]-1;
       end;
     i:=1;
     while a[i]<a[i+1] do
        begin
            j:=i+1;
            a[i]:=a[i]+a[j];
            a[j]:=a[i]-a[j];
            a[i]:=a[i]-a[j];
            b[i]:=b[i]+b[j];
            b[j]:=b[i]-b[j];
            b[i]:=b[i]-b[j];
            i:=i+1;
         end;
     i:=2;
     while a[i]<a[i+1] do
        begin
            j:=i+1;
            a[i]:=a[i]+a[j];
            a[j]:=a[i]-a[j];
            a[i]:=a[i]-a[j];
            b[i]:=b[i]+b[j];
            b[j]:=b[i]-b[j];
            b[i]:=b[i]-b[j];
            i:=i+1;
         end;
     write(t,' ');
     until (a[2]=0);
     if t<>b[1] then write(b[1]);
{     sleep(112121);}
{   close(input);
   close(output); }
end.

give me wrong test, please!