我这个程序,如果用样例测试,输出为
9 12 12 25 25 25 31 0 0 0
输出不正确,但我也不知道哪儿出问题了,求助求助!
#include<bits/stdc++.h>
using namespace std;
const int N= 10010;
int a[N],b[N],c[N];
struct node{
bool operator()(const pair<int,int> &a, const pair<int,int> &b)
{
return a.first > b.first;
}
};
priority_queue<pair<int,int>,vector<pair<int,int>>,node> q;
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i]>>c[i];
q.push({a[i]+b[i]+c[i],1});
}
for(int i=1;i<=m;i++)
{
pair<int,int> p = q.top();
q.pop();
cout<<p.first<<" ";
int x=p.second;
x++;
q.push({a[x]*x*x + b[x]*x + c[x],x});
}
return 0;
}