Codeforce 867 C. Ordering Pizza (思维题)
It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices.
It is known that the i-th contestant will eat si slices of pizza, and gain ai happiness for each slice of type 1 pizza they eat, and bi happiness for each slice of type 2 pizza they eat. We can order any number of type 1 and type 2 pizzas, but we want to buy the minimum possible number of pizzas for all of the contestants to be able to eat their required number of slices. Given that restriction, what is the maximum possible total happiness that can be achieved?
The first line of input will contain integers N and S (1 ≤ N ≤ 105, 1 ≤ S ≤ 105), the number of contestants and the number of slices per pizza, respectively. N lines follow.
The i-th such line contains integers si, ai, and bi (1 ≤ si ≤ 105, 1 ≤ ai ≤ 105, 1 ≤ bi ≤ 105), the number of slices the i-th contestant will eat, the happiness they will gain from each type 1 slice they eat, and the happiness they will gain from each type 2 slice they eat, respectively.
Print the maximum total happiness that can be achieved.
3 12
3 5 7
4 6 7
5 9 5
84
6 10
7 4 7
5 8 8
12 5 8
6 11 6
3 3 7
5 9 6
314
In the first example, you only need to buy one pizza. If you buy a type 1 pizza, the total happiness will be 3·5 + 4·6 + 5·9 = 84, and if you buy a type 2 pizza, the total happiness will be 3·7 + 4·7 + 5·5 = 74.
思路:
先假设全部吃类型一的披萨,再假设有一部分吃下了类型二的披萨,会多出多少。
二者之和就是答案。
代码:
#include<iostream>
#include<algorithm>
#define fuck(x) cout<<"x="<<x<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
struct node
{
ll x,s;
}t[maxn];; bool cmp(node a,node b)
{
if(a.x==b.x){return a.s>b.s;}
else return a.x>b.x;
} int main()
{
int n;
ll s;
scanf("%lld%lld",&n,&s);
int a,b;
ll ans=0;
ll sum=0;
for(int i=1;i<=n;i++){
scanf("%d%d%d",&t[i].s,&a,&b);
t[i].x=b-a;
ans+=t[i].s*a;sum+=t[i].s;
}
if(sum%s){
t[++n].s=s-sum%s;
t[n].x=0;
}
sort(t+1,t+1+n,cmp);
ll num=0,ans1=0;sum=0; for(int i=1;i<=n;i++){
if(num+t[i].s>=s){
ans1=max(ans1,(s-num)*t[i].x+sum);
ans1=max(ans1,((num+t[i].s)/s*s-num)*t[i].x+sum);
}
sum+=t[i].s*t[i].x;
num=(num+t[i].s)%s;
}
printf("%lld",ans+ans1);
}
Codeforce 867 C. Ordering Pizza (思维题)的更多相关文章
- ACM思维题训练 Section A
题目地址: 选题为入门的Codeforce div2/div1的C题和D题. 题解: A:CF思维联系–CodeForces -214C (拓扑排序+思维+贪心) B:CF–思维练习-- CodeFo ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...
- HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)
HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...
随机推荐
- windows 安装tensorflow
原文知乎:https://zhuanlan.zhihu.com/p/25778703 前言 看到Rstudio中开始支持Tensorflow,本人是欣喜若狂的,同时TensorFlow官网从16年9月 ...
- dw擴展jquery
https://jingyan.baidu.com/article/90895e0fbbb65764ec6b0bd1.html
- vue 子组件修改父组件传来的props值,报错
vue不推荐直接在子组件中修改父组件传来的props的值,会报错 [Vue warn]: Avoid mutating a prop directly since the value will be ...
- Python——Label控件说明
Anchor : 标签中文本的位置: background(bg)foreground(fg) :背景色:前景色: borderwidth(bd) :边框宽度: width .height ...
- do not track
privacy.trackingprotection.enabled
- JVM方法调用过程
JVM方法调用过程 重载和重写 同一个类中,如果出现多个名称相同,并且参数类型相同的方法,将无法通过编译.因此,想要在同一个类中定义名字相同的方法,那么它们的参数类型必须不同.这种方法上的联系就是重载 ...
- Comet OJ - Contest #0
A:化成x-√n=y+z-√4yz的形式,则显然n是完全平方数时有无数组解,否则要求n=4yz,暴力枚举n的因数即可.注意判断根号下是否不小于0. #include<iostream> # ...
- POJ3468/splay树/成段更新
板子题,正在努力看懂板子.. http://blog.csdn.net/acm_cxlove/article/details/7815019 http://www.cnblogs.com/kuangb ...
- Android EditView 获取焦点 不弹出软键盘
很简单的做法: 找到AndroidManifest.xml文件 然后在对应的activity中增加android:windowSoftInputMode="adjustPan" & ...
- IDM下载神器
破解版IDM 个人评价:基本上能满足日常下载需求,除bt.磁力外. 不管是在线视频, 还是音乐, 电子书, 统统都能下载, 还附有爬虫功能~~ 直接附链接: 百度云链接: https://pan.ba ...