当前位置:网站首页>D - Function(HDU - 6546)女生赛
D - Function(HDU - 6546)女生赛
2022-07-06 09:25:00 【是小张张呀 zsy】
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
struct node
{
ll a,b,c;
ll mark; //标记x每次加一函数的增长f(x+1)-f(x);
ll x;
bool operator<(const node &t) const{
return mark > t.mark;
}
};
int main()
{
ll n,m;
while(~scanf("%lld%lld",&n,&m))
{
priority_queue<node> pq;//自定义的优先队列;
ll ans=0;
for(int i=0;i<n;i++){
node t;
scanf("%lld%lld%lld",&t.a,&t.b,&t.c);
ans+=t.a+t.b+t.c; //当x等于一时;
t.x=1;
t.mark=t.a*(2*t.x+1)+t.b; //f(x+1)-f(x),增长量;
pq.push(t); //压入;
}
for(int i=0;i<m-n;i++){
node temp=pq.top();
//每次取增长1最少的函数,得x的值,然后再 temp.x++;
pq.pop();
temp.x++;
temp.mark=temp.a*(2*temp.x+1)+temp.b;//增长f(x+1)-f(x);
pq.push(temp);
ans+=temp.a*(2*temp.x-1)+temp.b;
//ans是f(x-1)的值,所以减去增长的量;
}
printf("%lld\n",ans);
}
return 0;
}
边栏推荐
- Hospital privacy screen Industry Research Report - market status analysis and development prospect forecast
- JS --- all basic knowledge of JS (I)
- STM32学习记录:输入捕获应用
- STM32 learning record: play with keys to control buzzer and led
- FSM and I2C experiment report
- JS --- all knowledge of JS objects and built-in objects (III)
- Learning record: understand systick system timer and write delay function
- ucorelab4
- LeetCode#118. Yanghui triangle
- Leetcode notes - dynamic planning -day7
猜你喜欢
ucore lab7
ucore lab 2
12306: mom, don't worry about me getting the ticket any more (1)
Brief introduction to libevent
How to become a good software tester? A secret that most people don't know
What is "test paper test" in software testing requirements analysis
ucore lab 2
JS --- detailed explanation of JS DOM (IV)
学习记录:串口通信和遇到的错误解决方法
Knowledge that you need to know when changing to software testing
随机推荐
Research Report on medical toilet industry - market status analysis and development prospect forecast
STM32 learning record: play with keys to control buzzer and led
Cost accounting [24]
Research Report on market supply and demand and strategy of geosynthetics industry in China
Your wechat nickname may be betraying you
学习记录:如何进行PWM 输出
学习记录:TIM—电容按键检测
动态规划前路径问题优化方式
Crawler series (9): item+pipeline data storage
[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)
程序员的你,有哪些炫技的代码写法?
Research Report of pharmaceutical solvent industry - market status analysis and development prospect prediction
ucore lab7
Research Report on market supply and demand and strategy of China's Medical Automation Industry
JS --- detailed explanation of JS DOM (IV)
What is "test paper test" in software testing requirements analysis
Brief introduction to libevent
ucore lab5
Jupyter installation and use tutorial
Research Report on medical anesthesia machine industry - market status analysis and development prospect prediction