cf 865 B. 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>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll n,s,m,a,b,cnta=,cntb=;
ll ans=,pos=,inf=;
vector<pair<ll,ll> >v[];
int main()
{
scanf("%lld%lld",&n,&s);
for(int i=;i<n;i++)
{
scanf("%lld%lld%lld",&m,&a,&b);
if(a>=b) ans+=m*a,cnta=(cnta+m)%s,v[].push_back(make_pair(a-b,m));
else ans+=m*b,cntb=(cntb+m)%s,v[].push_back(make_pair(b-a,m));
}
sort(v[].begin(),v[].end());
sort(v[].begin(),v[].end());
if(cnta+cntb>s) return *printf("%lld\n",ans);
for(int i=;i<v[].size();i++)
{
pos+=min(v[][i].second,cnta)*v[][i].first;
cnta-=min(cnta,v[][i].second);
}
for(int i=;i<v[].size();i++)
{
inf+=min(v[][i].second,cntb)*v[][i].first;
cntb-=min(cntb,v[][i].second);
}
printf("%lld\n",ans-min(inf,pos));
return ;
}
cf 865 B. Ordering Pizza的更多相关文章
- Codeforce 867 C. Ordering Pizza (思维题)
C. Ordering Pizza It's another Start[c]up finals, and that means there is pizza to order for the ons ...
- C - Ordering Pizza CodeForces - 867C 贪心 经典
C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...
- Codeforces Round #437 C. Ordering Pizza
题意: n个人吃披萨,总共有两种披萨,每种披萨都是有S块,给出每个人要吃的块数,吃第一种披萨能获得的happy值,吃第二种披萨能获得的happy值,问你,在购买的披萨数最少的情况下能获得的最大的总的h ...
- 【Codeforces Round #437 (Div. 2) C】 Ordering Pizza
[链接]h在这里写链接 [题意] 给你参赛者的数量以及一个整数S表示每块披萨的片数. 每个参数者有3个参数,si,ai,bi; 表示第i个参赛者它要吃的披萨的片数,以及吃一片第 ...
- Codeforces Round #437 (Div. 2)[A、B、C、E]
Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...
- CF泛做
CF Rd478 Div2 A Aramic script 题意:给定几个字符串,去重后,求种类 思路:直接map乱搞 #include<bits/stdc++.h> using name ...
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)
Problem A Between the Offices 水题,水一水. #include<bits/stdc++.h> using namespace std; int n; ]; i ...
- Write-up-Bob_v1.0.1
关于 下载地址:点我 哔哩哔哩视频:哔哩哔哩 信息收集 网卡:vmnet8:IP在192.168.131.1/24 ➜ ~ ip a show dev vmnet8 5: vmnet8: <BR ...
- UVA 565 565 Pizza Anyone? (深搜 +位运算)
Pizza Anyone? You are responsible for ordering a large pizza for you and your friends. Each of th ...
随机推荐
- 紫书 习题8-4 UVa 11491 (贪心)
题意:给你一个数, 要求删去一些数字, 使得剩下的数字最大. 这道题用贪心解决. 大家想一想, 两个数比较大小, 肯定先比较第一位的数,然后依次比较第二位,以此类推. 既然我们要保证最后的数字最大, ...
- SSIS安装以及安装好找不到商业智能各种坑
原文:SSIS安装以及安装好找不到商业智能各种坑 这两天为了安装SSIS,各种头疼.记录一下,分享给同样遇到坑的.. 安装SSIS需要几个步骤. 先说一下我的情况,安装SQL的时候,一直默认下一步,没 ...
- Tarjan 割点割边【模板】
#include <algorithm> #include <cstring> #include <cstdio> using namespace std; +); ...
- 在VS2013中配置QT5 win7_64
转自 在VS2013中配置QT5 win7_64 环境: win x64 + vs2013+QT5+vs_addin 下面示例正确配置QT以及VS2013 + QT Addin开发环境: 下载VS20 ...
- Python 入门学习 -----变量及基础类型(元组,列表,字典,集合)
Python的变量和数据类型 1 .python的变量是不须要事先定义数据类型的.能够动态的改变 2. Python其中一切皆对象,变量也是一个对象,有自己的属性和方法 我们能够通过 来查看变量的类型 ...
- Linux在中国的没落
6月23日,Linux kernel 4.1(LTS)公布.在国际自由软件世界引起热烈反响. 反观我们国内,官方机构没有不论什么动静:在民间,Linux激情已经消失.与十几年前相比.Linux在国内已 ...
- 2014 百度之星 1003 题解 Xor Sum
Xor Sum Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheu ...
- xp秘钥
TDCXC-M9FW9-3HQ28-CPXYR-YXQ3QCCBDF-9W9T8-K8B7M-83HJM-X2MCWP3MF6-BTDKT-KR7YF-X4BM9-4HD9TMCCWF-42JGF-W ...
- 安卓开发--scrollview
package com.cnn.scrollviewdemo01; import android.R.integer; import android.annotation.SuppressLint; ...
- ListView 适配器实现getviewtypcount() 数组越界IndexOutOfBoundException
ListView中Item的多布局显示,需要用到了getViewTypecount和getItemViewType这两个重写方法,但是做完后出现了如下提示错误:java.lang.ArrayIndex ...