题意: 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. Codeforces1062A. A Prank(暴力)

    题目链接:传送门 题目: A. A Prank time limit per test second memory limit per test megabytes input standard in ...

  2. 421. Maximum XOR of Two Numbers in an Array

    这题要求On时间复杂度完成, 第一次做事没什么思路的, 答案网上有不贴了, 总结下这类题的思路. 不局限于这个题, 凡是对于这种给一个  数组,  求出 xxx 最大值的办法, 可能上来默认就是dp, ...

  3. xamarin android 报错 Could not load assembly 'Xamarin.Android.Support.v7.AppCompat

    严重性 代码 说明 项目 文件 行 禁止显示状态 错误 Exception while loading assemblies: System.IO.FileNotFoundException: Cou ...

  4. easyui-datebox 点击事件

    <div class="form-group col-xs-5 col-md-5 col-lg-6" style = "margin-left: 0px;" ...

  5. DHCP Option43配置

    在配置Option 43之前,需要保证:1. AP与DHCP服务器之间路由可达,即AP可以获取到IP地址.2. AP与AC之间路由可达,保证AP获取到AC地址后,能够与AC交互信息,建立CAPWAP隧 ...

  6. C# 代码小技巧

    一 .自动属性. 1.vs下输入prop,Tab键就出现了.   2.有了自动属性,我们不用再额外为一个类的每个公共属性定义一个私有字段(实际上没多大用处的字段), 但是通过反射还是可以看到对应的私有 ...

  7. Word中一条删除不掉的单或双横线的解决办法

    Word中一条删除不掉的单或双横线 有时你或许会遇到这样一种情况:在word中,有一条单或双横线怎么都删除不了,并且具有这样的特点: 在上面输入文字,横线会自动下调一行,如果文章过页,每页的尾部会有一 ...

  8. studio--常见设置

    13.Butterknife插件:zelezny 12.android studio怎么设置打开项目时打开项目列表? 11.stuido   代码背景颜色设置为护眼模式 ======== 13.But ...

  9. 编译CDH的spark1.5.2

    手动安装mvn大于3.3.3版本 下载解压,修改~/.bash_rc export MAVEN_HOME=/usr/local/apache-maven-3.3.9 export PATH=$MAVE ...

  10. [转] SQL日期函数dayadd/datediff/datepart

    函数一: CREATE OR REPLACE FUNCTION dayadd(p_Component varchar2, p_Number number, p_Date date) RETURN DA ...