题意: n个人吃披萨,总共有两种披萨,每种披萨都是有S块,给出每个人要吃的块数,吃第一种披萨能获得的happy值,吃第二种披萨能获得的happy值,问你,在购买的披萨数最少的情况下能获得的最大的总的happy值是多少(披萨可以买任意多个,吃不完也行 2333333)

Examples
Input
3 12
3 5 7
4 6 7
5 9 5
Output
84
Input
6 10
7 4 7
5 8 8
12 5 8
6 11 6
3 3 7
5 9 6
Output
314

思路:首先肯定是每个人都吃happy值更大的那一种披萨最优,但是有一个问题,可能会多出一点零头,那么我们记为sum1和sum2。
   如果sum1+sum2>S,那么这些零头肯定是要买两个披萨的,不如就各买各的,那么答案就是ans;
   但是如果sum1+sum2<=S,那么就要一起买一个披萨了,这样的话就用ans-min(让买第一种披萨的去买第二种的差值,
   让买第二种披萨的去买第一种的差值),
    这样算出来的结果就是答案了。
   (用结构体保存一下a,b,差值,然后按差值从小到大来排序,肯定是让差值小的最后买这样才最划算,因为如果要买另外一
    个这样损失最小)
   for(int i=0;i<n1;i++){
            ans1+=min(sum1,t1[i].s)*t1[i].c;
            sum1-=min(sum1,t1[i].s);
        }
    for(int i=0;i<n2;i++){
            ans2+=min(sum2,t2[i].s)*t2[i].c;
            sum2-=min(sum2,t2[i].s);
        }
    这两句话很关键是从一个帖子看到的23333。 代码: #include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e5+5; struct node{
    long long s,a,b,c;
}t1[maxn],t2[maxn];
bool cmp(node x,node y){
    return x.c<y.c;
} int main(){
    long long n,S,n1=0,n2=0,sum1=0,sum2=0,ans=0,ans1=0,ans2=0,x,y,z;
    cin>>n>>S;
    for(int i=0;i<n;i++){
        cin>>x>>y>>z;
        if(y>z){
            t1[n1].s=x;
            t1[n1].a=y;
            t1[n1].b=z;
            t1[n1].c=y-z;
            ans+=t1[n1].a*t1[n1].s;
            sum1=(sum1+t1[n1].s)%S;
            n1++;
        }
        else {
            t2[n2].s=x;
            t2[n2].a=y;
            t2[n2].b=z;
            t2[n2].c=z-y;
            ans+=t2[n2].b*t2[n2].s;
            sum2=(sum2+t2[n2].s)%S;
            n2++;
        }
    }
    if(sum1+sum2>S){
        cout<<ans<<endl;
    }
    else {
        sort(t1,t1+n1,cmp);
        for(int i=0;i<n1;i++){
            ans1+=min(sum1,t1[i].s)*t1[i].c;
            sum1-=min(sum1,t1[i].s);
        }
        sort(t2,t2+n2,cmp);
        for(int i=0;i<n2;i++){
            ans2+=min(sum2,t2[i].s)*t2[i].c;
            sum2-=min(sum2,t2[i].s);
        }
        if(ans1<ans2)ans-=ans1;
        else ans-=ans2;
        cout<<ans<<endl;
    }
    return 0;
}

Codeforces Round #437 C. Ordering Pizza的更多相关文章

  1. Codeforces Round #437 (Div. 2)[A、B、C、E]

    Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...

  2. 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 ...

  3. 【Codeforces Round #437 (Div. 2) C】 Ordering Pizza

    [链接]h在这里写链接 [题意]     给你参赛者的数量以及一个整数S表示每块披萨的片数.     每个参数者有3个参数,si,ai,bi;     表示第i个参赛者它要吃的披萨的片数,以及吃一片第 ...

  4. Codeforces Round #437 Div. 1

    A:显然构造一组只包含1和2面值的数据即可. #include<iostream> #include<cstdio> #include<cmath> #includ ...

  5. Codeforces Round #437 E. Buy Low Sell High

    题意:买卖股票,给你n个数,你可以选择买进或者卖出或者什么都不做,问你最后获得的最大收益是多少. Examples Input 910 5 4 7 9 12 6 2 10 Output 20 Inpu ...

  6. Codeforces Round #437 B. Save the problem!

    题意: 给你一个方案数,要求你输出满足该条件的总金额,面值数,和各个面值是多少,答案有多个,随便输出一个即可. Examples Input 18 Output 30 41 5 10 25 Input ...

  7. Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E

    题意:减前面的数,加后面的数,保证最后不剩下数,加减次数要相同: 题解:emmmmm,看出是个贪心,先对价值排序,相同就对下标排序,规律是每次找第一个,然后从后往前找没有使用过的下表比他大的第一个,相 ...

  8. 【Codeforces Round #437 (Div. 2) A】Between the Offices

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 在这里写题解 [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using n ...

  9. 【Codeforces Round #437 (Div. 2) B】Save the problem!

    [链接]h在这里写链接 [题意]     给你一个金额N,和硬币的类型总数M;     (完全背包),然后问你组成N的方案数.     使得,用这些硬币组成价值为N的金额的方案数为A;     现在A ...

随机推荐

  1. Python之os模块和sys模块

    OS模块:print(os.getcwd())os.chdir('..') #返回上一层目录print(os.getcwd()) os.makedirs('xxxx') #生成多级递归目录os.mkd ...

  2. 分布式高并发下Actor模型

    分布式高并发下Actor模型 写在开始 一般来说有两种策略用来在并发线程中进行通信:共享数据和消息传递.使用共享数据方式的并发编程面临的最大的一个问题就是数据条件竞争.处理各种锁的问题是让人十分头痛的 ...

  3. 五分钟带你走入MP

    一.MyBatis-Plus简介 1.1MyBatis-Plus是什么? MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化 ...

  4. linux4.15.1编译init/mounts报错

    AR init/mounts.o arm-linux-ar: illegal option -- T Usage: arm-linux-ar [emulation options] [-]{dmpqr ...

  5. Unity在WPF中的应用

    1. 本文的实现类继承于IRepository using System; using System.Linq; using System.Linq.Expressions; using Zhang. ...

  6. mysql 分组排序前n + 长表转宽表

    MySQL数据库优化的八种方式(经典必看) 建表 CREATE TABLE if not EXISTS `bb` ( `id` int not null primary key auto_increm ...

  7. unity的一些tips

    主要是我知乎上回答的一个关于unity的tip,备忘. 说说我所看到unity相关的,不好的习惯: 1 尽量不要在Awake(), start()等函数内加入业务逻辑的初始化代码.首先无法简便的直接启 ...

  8. 如何在Windows命令行(DOS界面)中调用 编译器 来编译C/C++源程序

    首先说明一下背景: 为什么要在DOS界面编译C/C++源程序?有很多现成的开发环境(IDE)如:vs, vc++等,这些开发环境集成了编译,调试,使用起来很方便,而且图形化操作界面,简洁明了.但是在开 ...

  9. scoping作用域,anonymous function匿名函数,built-in functions内置函数

    作用域练习1 def test1(): print('in the test1') def test(): print('in the test') return test1 res = test() ...

  10. 黄聪:用 CSS 实现元素垂直居中,有哪些好的方案?

    1.不知道自己高度和父容器高度的情况下, 利用绝对定位只需要以下三行: parentElement{ position:relative; } childElement{ position: abso ...