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 ...
随机推荐
- Mybatis之执行insert、update和delete操作时自动提交
单独使用Mybaits,而没有集成Spring的话,执行insert.update和delete操作是不会自动提交的,即执行语句后不会在数据库有对应的数据变化. 解决这样的方法就是打开自动提交开关,在 ...
- 学习 Spring (六) 自动装配
Spring入门篇 学习笔记 No: (默认)不做任何操作 byName: 根据属性名自动装配.此选项将检查容器并根据名字查找与属性完全一致的 bean,并将其与属性自动装配 byType: 如果容器 ...
- AgilePoint数据库模式中当前所有表的列表
表名 描述 WF_ACTIVITY_INSTS 包含有关活动实例的信息. WF_ASSIGNED_OBJECTS 包含有关用户角色的分配对象的信息. WF_AUDIT_TRAILS 包含有关流程模板的 ...
- servlet篇 之 servlet的访问
三:servlet的访问 使用web.xml文件中的这个<url-pattern>标签中的映射路径,来访问servlet 6.1 在浏览器的地址栏中,直接输入servlet映射的路径来访问 ...
- django CBV视图源码分析
典型FBV视图例子 url路由系统 from django.conf.urls import url from django.contrib import admin from luffycity.v ...
- Javascript和Jquery语法对比总结
目的 相信大家都知道jq是js的一个类库,是为了方便我们开发前端,但是笔者在刚开始学习js和jq时经常将两者的语法记混和混用,所以整理下两者实现相同功能之前的语法区别. 声明变量 javascript ...
- delegate--委托
delegate--委托 (可以把委托看成用来执行方法的一个东西) eg: namespace delegateTest{ delegate double MathsOp(double x); cla ...
- HTML查漏补缺 【未完】
1.命名锚 HTML 链接 - name 属性 name 属性规定锚(anchor)的名称. 您可以使用 name 属性创建 HTML 页面中的书签. 书签不会以任何特殊方式显示,它对读者是不可见的. ...
- VM磁盘映射共享方法,要求文件系统必须一致
如果主机是window系统,那么虚拟机也应该是Windows系统,不然不起作用
- Joseph POJ - 1012 约瑟夫环递推
题意:约瑟夫环 初始前k个人后k个人 问m等于多少的时候 后k个先出去 题解:因为前k个位置是不动的,所以只要考虑每次递推后的位置在不在前面k个就行 有递推式 ans[i]=(ans[i-1]+m ...