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.  
  16. int n; cin >> n;
  17. for (int i = 0; i < n; ++i) {
  18. cin >> a[i] >> b[i] >> c[i];
  19. }
  20. int q; cin >> q;
  21. vector<array<LL, 2>> vals(n);
  22. for (int j = 0; j < q; ++j) {
  23. int pp; cin >> pp;
  24. int tt; cin >> tt;
  25. for (LL i = 0; i < n; ++i) {
  26. vals[i] = {-eval(i, tt), i+1};
  27. }
  28. nth_element(begin(vals), begin(vals)+pp-1, end(vals));
  29. cout << vals[pp-1][1] << "\n";
  30. }
  31. }
  32.  
Success #stdin #stdout 0.01s 5320KB
stdin
5
2 4 6
3 3 8
4 0 5
1 4 6
7 7 4
3
2 0
1 1
4 2
stdout
1
5
3