fork download
  1. program formula1;
  2. type elenco = array[1..200000] of qword;
  3. var N,Q,i,j, minimo :qword;
  4. a, b, c :array[1..2000] of qword;
  5. p, t, valore, id : elenco;
  6.  
  7. function calcolavalore (aa,bb,cc,tt:qword): qword;
  8.  
  9. begin
  10. calcolavalore:=aa*tt*tt+bb*tt+cc;
  11. end;
  12.  
  13. Procedure scambia (var aa,bb: qword);
  14. var x:qword;
  15. begin
  16. x:=aa;
  17. aa:=bb;
  18. bb:=x;
  19. end;
  20. Procedure ordinamento (estremoi,estremos: qword; var v : elenco;var u : elenco; ordinato:boolean);
  21. var inf, sup, medio:qword;
  22. pivot :qword;
  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.  
  46. begin
  47. (*assign(input, 'input.txt'); reset(input);
  48.   assign(output, 'output.txt'); rewrite(output); *)
  49. readln(N);
  50. for i:=1 to N do begin readln(a[i],b[i],c[i]); id[i]:=i; end;
  51. readln(Q);
  52. for i:=1 to Q do
  53. begin
  54. readln (p[i],t[i]);
  55. for j:=1 to N do valore[j]:=calcolavalore(a[j],b[j],c[j],t[i]);
  56. ordinamento(1,N,valore, id, true);
  57. j:=1; minimo:=id[p[i]];
  58. while j<=N do begin
  59. if valore[j]<>valore[p[i]] then j:=j+1
  60. else
  61. if id[j]<minimo then begin minimo:=id[j]; j:=j+1; end
  62. else j:=j+1;
  63.  
  64. end;
  65.  
  66. writeln(minimo);
  67. for j:=1 to N do begin valore[j]:=0; id[j]:=j; end;
  68. end;
  69.  
  70. end.
Success #stdin #stdout 0s 5328KB
stdin
5
2 4 6
3 3 8
4 0 6
1 4 1
7 7 6
5
4 0
1 1
4 2
4 3
5 4
stdout
1
5
1
1
4