fork download
  1. program formula1;
  2. type elenco = array[1..2000,1..2] of int64;
  3. var N,Q,i,j, p,t,minimo :int64;
  4. a, b, c :array[1..2000] of int64;
  5. valore : elenco;
  6.  
  7. function calcolavalore (aa,bb,cc,tt:int64): int64;
  8.  
  9. begin
  10. calcolavalore:=(aa*tt*tt+bb*tt+cc)*(-1);
  11. end;
  12.  
  13. procedure nth_element(l, k, r: int64);
  14. var ii, jj, x, tmp: int64;
  15. begin
  16. ii := l; jj := r;
  17. x := valore[jj][1];
  18. repeat
  19. while valore[ii][1] < x do inc(ii);
  20. while x < valore[jj][1] do dec(jj);
  21. if ii <= jj then
  22. begin
  23. tmp := valore[ii][1]; valore[ii][1] := valore[jj][1]; valore[jj][1] := tmp;
  24. tmp := valore[ii][2]; valore[ii][2] := valore[jj][2]; valore[jj][2] := tmp;
  25. inc(ii); dec(jj);
  26. end;
  27. until ii > jj;
  28. if jj >= k then nth_element(l, k, jj);
  29. if ii <= k then nth_element(ii, k, r);
  30. end;
  31.  
  32. begin
  33. (*assign(input, 'input.txt'); reset(input);
  34.   assign(output, 'output.txt'); rewrite(output);*)
  35. readln(N);
  36. for i:=1 to N do readln(a[i],b[i],c[i]);
  37. readln(Q);
  38. for i:=1 to Q do
  39. begin
  40. readln (p,t);
  41. for j:=1 to N do begin valore[j][1]:=calcolavalore(a[j],b[j],c[j],t); valore[j][2]:=j; end;
  42. for j:=1 to N do
  43. nth_element(1, p, N);
  44. writeln(valore[p][2]);
  45. for j:=1 to N do begin valore[j][1]:=0; valore[j][2]:=j; end;
  46. end;
  47.  
  48. end.
Success #stdin #stdout 0.01s 5284KB
stdin
5
2 4 6
3 3 8
4 0 5
1 4 6
7 7 6
1
4 0
stdout
1