fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using LL = long long;
  4.  
  5. static constexpr int T = 1e6;
  6. static constexpr int N = 2000;
  7.  
  8. static int a[N], b[N], c[N];
  9.  
  10. static LL eval(int i, LL t) {
  11. return a[i]*t*t + b[i]*t + c[i];
  12. }
  13.  
  14. int main() {
  15. int n; cin >> n;
  16. for (int i = 0; i < n; ++i) {
  17. cin >> a[i] >> b[i] >> c[i];
  18. }
  19. int q; cin >> q;
  20. vector<array<LL, 2>> vals(n);
  21. for (int j = 0; j < q; ++j) {
  22. int pp; cin >> pp;
  23. int tt; cin >> tt;
  24. for (LL i = 0; i < n; ++i) {
  25. vals[i] = {-eval(i, tt), i+1};
  26. }
  27. nth_element(begin(vals), begin(vals)+pp-1, end(vals));
  28. cout << vals[pp-1][1] << "\n";
  29. }
  30. }
  31.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty