1 solutions
-
3
#include<bits/stdc++.h> using namespace std; const int N=100010; int a[N],b[N],c[N]; int main() { int n,m; cin>>n>>m; for(int i=1;i<=n;i++) //获取函数 { cin>>a[i]>>b[i]>>c[i]; } priority_queue<int> q; for(int x=1;x<=m;x++) //至多m次操作 { bool st=0; //有没有元素更新 for(int i=1;i<=n;i++) { int t=a[i]*x*x+b[i]*x+c[i]; if(q.size()<m) //如果当前元素小于m个,直接插入 { q.push(t); st=1; }else if(t<q.top()) //当前元素大于等于m个,但是当前函数值小于已有的最大值(更新) { q.push(t); q.pop(); st=1; } } if(st==0) break; //大根堆中没有元素更新了 } priority_queue<int,vector<int>,greater<int> > q2; //方便从小到大输出 while(q.size()) { q2.push(q.top()); q.pop(); } while(q2.size()) { cout<<q2.top()<<" "; q2.pop(); } return 0; }
- 1
Information
- ID
- 966
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- (None)
- # Submissions
- 17
- Accepted
- 10
- Uploaded By