codeforces 865B. Ordering Pizza
来源:互联网 发布:单片机程序烧入不进去 编辑:程序博客网 时间:2024/05/16 07:52
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 123 5 74 6 75 9 5
84
6 107 4 75 8 812 5 86 11 63 3 75 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.
题意:
有N个参赛者,需要准备披萨,有两种披萨,每一种披萨都有S片,分配给这些参赛者,每一个参赛者需要吃的披萨数量不定,接下来N行是每一个参赛者的信息,分别是需要吃的片数,吃了第一种获得的幸福感,吃了第二种披萨的幸福感。求用最少的可以满足这些需求的披萨,求出其中最大的幸福值。
代码:
#include<bits/stdc++.h>using namespace std;typedef long long ll;vector< pair<ll,ll> >a,b;ll n,s,ans,na,nb,ta,tb;signed main(){ll ss,aa,bb;pair<ll,ll>k;scanf("%I64d%I64d",&n,&s);for(int i=1;i<=n;i++){scanf("%lld%lld%lld",&ss,&aa,&bb);if(aa>bb){ans+=ss*aa;na+=ss;k.first=aa-bb;k.second=ss;a.push_back(k);}else{ans+=ss*bb;nb+=ss;k.first=bb-aa;k.second=ss;b.push_back(k);}}cout<<na<<" "<<nb<<endl;na%=s;nb%=s;cout<<ans<<endl;if(na+nb>s){printf("%lld\n",ans);return 0;}sort(a.begin(),a.end());sort(b.begin(),b.end());for(int i=0;na;i++){ta+=min(na,a[i].second)*a[i].first;na-=min(na,a[i].second);cout<<"ta "<<ta<<" "<<"na "<<na<<endl;}for(int i=0;nb;i++){tb+=min(nb,b[i].second)*b[i].first;nb-=min(nb,b[i].second);cout<<"tb "<<tb<<" "<<"nb "<<nb<<endl;}ans-=min(ta,tb);printf("%I64d\n",ans);return 0;}
- codeforces 865B. Ordering Pizza
- CodeForces 867C Ordering Pizza
- codeforces 867 C Ordering Pizza
- Codeforces Round #437-贪心-C. Ordering Pizza
- Codeforces Round #437 Div. 2 C. Ordering Pizza
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- Ordering Pizza(贪心)
- Codeforces 842B. Gleb And Pizza 模拟
- Codeforces 842 B Gleb And Pizza
- Codeforces Round #430 (Div. 2) B. Gleb And Pizza
- Codeforces Round #430 (Div. 2) B. Gleb And Pizza
- Codeforces Round #430 (Div. 2) B. Gleb And Pizza(数论)
- Codeforces Round #430 (Div. 2) B. Gleb And Pizza
- (几何题)Codeforces 430 B. Gleb And Pizza
- codeforces A. Pizza Separation
- Pizza Separation CodeForces
- B. Gleb And Pizza
- PIZZA
- hdu 5288 简单思维 贡献思维
- 198. House Robber
- 更新
- Android自定义控件总结
- Jzoj3806 小X 的道路修建
- codeforces 865B. Ordering Pizza
- 213. House Robber II
- 「Machine Learning」K-Means Clustering Algorithm from CS229 Lecture Notes
- 集合框架总结
- 使用knowledge-based方法提升词向量的生成质量
- 设计模式读书笔记-----代理模式
- Python3 函数
- 更新
- codeforces 865 C. Buy Low Sell High