fork download
  1. Program tournament;
  2.  
  3. const
  4. MAXN = 131072;
  5.  
  6. var
  7. N, i, h,k, numeroconcorrenti,runnerup, winner : LongInt;
  8. P,tabellone : Array[0..MAXN-1] of LongInt;
  9.  
  10. begin
  11. {
  12.   uncomment the two following lines if you want to read/write from files
  13.   assign(input, 'input.txt'); reset(input);
  14.   assign(output, 'output.txt'); rewrite(output);
  15. }
  16.  
  17. ReadLn(N);
  18.  
  19. for i:=0 to N-1 do
  20. begin
  21. Read(P[i]);
  22. tabellone[i]:=i;
  23. end;
  24. ReadLn();
  25. numeroconcorrenti:=N;
  26. winner := 0;
  27. runnerup := 0;
  28. while numeroconcorrenti>2 do
  29. begin
  30. i:=0; h:=0;
  31. while i< numeroconcorrenti-1 do
  32. begin
  33. if P[tabellone[i]]>P[tabellone[i+1]] then tabellone[h]:=tabellone[i]
  34. else tabellone[h]:=tabellone[i+1];
  35. h:=h+1; i:=i+2;
  36. end;
  37. numeroconcorrenti:=numeroconcorrenti div 2;
  38. end;
  39. if P[tabellone[0]]>P[tabellone[1]] then begin winner:= tabellone[0];runnerup:=tabellone[1]; end
  40. else begin winner:= tabellone[1];runnerup:=tabellone[0]; end;
  41. writeLn(winner, ' ', runnerup);
  42. end.
  43.  
Success #stdin #stdout 0s 5272KB
stdin
8
7 4 10 8 1 6 3 15
stdout
7 2