有n个函数,分别为F1,F2,…,Fn。定义Fi(x)=Ai*x^2+Bi*x+Ci(x∈N*)。给定这些Ai、Bi和Ci,请求出所有函数的所有函数值中最小的m个(如有重复的要输出多个)。
【输入格式】
第一行输入两个正整数n和m。
以下n行每行三个正整数,其中第i行的三个数分别位Ai、Bi和Ci。输入数据保证Ai<=10,Bi<=100,Ci<=10 000。
【输出格式】
输出将这n个函数所有可以生成的函数值排序后的前m个元素。
这m个数应该输出到一行,用空格隔开。
【输入样例】
3 10
4 5 3
3 4 5
1 7 1
【输出样例】
9 12 12 19 25 29 31 44 45 54
【数据规模】
n,m<=10 000
#include<iostream>
#include<queue>
using namespace std;
int a[10005],b[10005],c[10005];
struct node{
int nn,xh,v;
bool operator<(const node &s) const{
return v>s.v;
}
};
priority_queue<node> h;
int qh(int i,int t)
{ return a[i]*t*t+b[i]*t+c[i];
}
int main()
{ int n,m;
cin>>n>>m;
for (int i=1;i<=n;++i)
cin>>a[i]>>b[i]>>c[i];
for (int i=1;i<=n;++i)
h.push((node){i,1,qh(i,1)});
while (m>0)
{ node t=h.top();
h.pop();
cout<<t.v<<" ";
h.push((node){t.nn,t.xh+1,qh(t.nn,t.xh+1)});
--m;
}
}