当前位置:网站首页>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;
}
边栏推荐
- ucore lab 2
- 动态规划前路径问题
- Market trend report, technical innovation and market forecast of lip care products in China and Indonesia
- Research Report on market supply and demand and strategy of Chinese hospital cleaning chemicals industry
- Eslint--- error: newline required at end of file but not found (EOL last) solution
- LeetCode#237. Delete nodes in the linked list
- Lab 8 file system
- 程序员的你,有哪些炫技的代码写法?
- LeetCode#198. raid homes and plunder houses
- Accounting regulations and professional ethics [2]
猜你喜欢
The wechat red envelope cover designed by the object is free! 16888
What are the commonly used SQL statements in software testing?
Your wechat nickname may be betraying you
[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)
What are the software testing methods? Show you something different
MATLAB实例:阶跃函数的两种表达方式
C语言必背代码大全
Eslint--- error: newline required at end of file but not found (EOL last) solution
STM32学习记录:输入捕获应用
ucore Lab 1 系统软件启动过程
随机推荐
JS --- detailed explanation of JS facing objects (VI)
12306: mom, don't worry about me getting the ticket any more (1)
通俗地理解什么是编程语言
Automated testing problems you must understand, boutique summary
Jupyter installation and use tutorial
[C language] twenty two steps to understand the function stack frame (pressing the stack, passing parameters, returning, bouncing the stack)
JS --- all knowledge of JS objects and built-in objects (III)
Learning record: Tim - capacitive key detection
The most detailed postman interface test tutorial in the whole network. An article meets your needs
学习记录:使用STM32外部输入中断
数据在内存中的存储&载入内存,让程序运行起来
ucore lab5
力扣刷题记录--完全背包问题(一)
Learning record: STM32F103 clock system overview working principle
LeetCode#412. Fizz Buzz
Optimization method of path problem before dynamic planning
Research Report on pharmaceutical R & D outsourcing service industry - market status analysis and development prospect forecast
Research Report on market supply and demand and strategy of China's Medical Automation Industry
Cost accounting [13]
Crawler series of learning while tapping (3): URL de duplication strategy and Implementation