rt。感觉实现得很怪但是就是过了而且跑得飞快。
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e4 + 5;
int n, m, a, b, c, ans[N];
priority_queue<int> q;
signed main() {
ios_base :: sync_with_stdio(NULL);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m;
for(int i = 1 ; i <= n ; ++ i) {
cin >> a >> b >> c;
for(int j = 1 ; j <= 1e9 ; ++ j) {
int res = a * j * j + b * j + c;
if(q.size() < m) q.push(res);
else if(res < q.top()) q.pop(), q.push(res);
else break;
}
}
int cnt = 0;
while(! q.empty()) ans[++ cnt] = q.top(), q.pop();
sort(ans + 1, ans + 1 + cnt);
for(int i = 1 ; i <= m ; ++ i)
cout << ans[i] << ' ';
return 0;
}