fork download
  1. program formula1;
  2. type elenco = array[1..2000] of int64;
  3. var N,Q,i,j,h :longint;
  4. a, b, c, valore :array[1..2000] of int64;
  5. p, t, id : elenco;
  6.  
  7. function calcolavalore (aa,bb,cc,tt:int64): int64;
  8.  
  9. begin
  10. calcolavalore:=aa*tt*tt+bb*tt+cc;
  11. end;
  12.  
  13. Procedure scambia (var aa,bb: int64);
  14. var x:int64;
  15. begin
  16. x:=aa;
  17. aa:=bb;
  18. bb:=x;
  19. end;
  20. Procedure ordinamento (estremoi,estremos: int64; var v : elenco;var u : elenco; ordinato:boolean);
  21. var inf, sup, medio:int64;
  22. pivot :int64;
  23. begin
  24. inf:=estremoi;
  25. sup:=estremos;
  26. medio:= (estremoi+estremos) div 2;
  27. pivot:=v[medio];
  28. repeat
  29. if (ordinato) then
  30. begin
  31. while (v[inf]>pivot) do inf:=inf+1;
  32. while (v[sup]<pivot) do sup:=sup-1;
  33. end;
  34. if inf<=sup then
  35. begin
  36. scambia(v[inf],v[sup]);
  37. scambia(u[inf],u[sup]);
  38. inf:=inf+1;
  39. sup:=sup-1;
  40. end;
  41. until inf>sup;
  42. if (estremoi<sup) then ordinamento(estremoi,sup,v,u,ordinato);
  43. if (inf<estremos) then ordinamento(inf,estremos,v,u,ordinato);
  44. end;
  45. begin
  46. readln(N);
  47. for i:=1 to N do begin readln(a[i],b[i],c[i]); id[i]:=i; end;
  48. readln(Q);
  49. for i:=1 to Q do
  50. begin
  51. readln (p[i],t[i]);
  52. for j:=1 to N do valore[j]:=calcolavalore(a[j],b[j],c[j],t[i]);
  53. ordinamento(1,N,valore, id, true);
  54. writeln(id[p[i]]);
  55. for j:=1 to N do begin valore[j]:=0; id[j]:=j; end;
  56. end;
  57.  
  58. end.
Success #stdin #stdout 0s 5320KB
stdin
5
2 4 6
3 3 8
4 0 5
1 4 1
7 7 4
5
4 0
1 1
4 2
4 3
5 4

stdout
5
5
3
1
4