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