Background \text{Background} Background
1. CSDN’s been upgraded today. There’s one MORE ad for each passage. \text{1. CSDN's been upgraded today. There's one MORE ad for each passage.} 1. CSDN’s been upgraded today. There’s one MORE ad for each passage.
2. Jane Zhang’s released her new Album on Apr 27th. \text{2. Jane Zhang's released her new Album on Apr 27th.} 2. Jane Zhang’s released her new Album on Apr 27th.
3. That Github Medal still have NOT got to my pocket yet. \text{3. That Github Medal still have NOT got to my pocket yet.} 3. That Github Medal still have NOT got to my pocket yet.
Given m quadratic function, their decision space is [1,100]. Please compute \text{Given }m\text{ quadratic function, their decision space is [1,100]. Please compute} Given m quadratic function, their decision space is [1,100]. Please compute
the mininum m function values. \text{the mininum }m\text{ function values.} the mininum m function values.
Solution \text{Solution} Solution
Use \text{Use } Use priority_queue to solve this problem. \text{ to solve this problem.} to solve this problem.
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
#define reg register
typedef long long ll;
int n, m;
int a[ 10010 ] , b[ 10010 ] , c[ 10010 ] ;
priority_queue< ll> q;
int main ( ) {
scanf ( "%d%d" , & n, & m) ;
for ( reg int i= 1 ; i<= n; ++ i) {
scanf ( "%d%d%d" , & a[ i] , & b[ i] , & c[ i] ) ;
for ( reg int j= 1 ; j<= 100 ; ++ j)
q. push ( - ( ( ll) a[ i] * j* j+ b[ i] * j+ c[ i] ) ) ;
}
for ( reg int i= 1 ; i<= m; ++ i) {
printf ( "%lld " , - q. top ( ) ) ;
q. pop ( ) ;
}
}