传送门

按理说想到转化问题之后就不难了吧,可是我还是不会写

一个很容易想到的转化就是差分,将银币数和铜币数都减去金币数,这样就转化为\(x+y+z\)个钱币选\(y\)个银币和\(z\)个铜币的最大数量了

然后我这个菜逼就不会做了

设总钱币数为\(n\),银币\(x[i]\)个,铜币\(y[i]\)个,就可以按\(x[i]-y[i]\)排序

然后很显然的就是一定是前\(k\)个选银币,后\(n-k\)个选铜币(显而易见的贪心)

枚举\(k\),用一个堆来维护就好了

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
void read(int &x){
char ch;bool ok;
for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1e5+10;
int x,y,z,n;long long ans,sum[maxn],num;
struct oo{int x,y;}a[maxn];
bool cmp(oo a,oo b){return a.x-a.y<b.x-b.y;}
priority_queue<int,vector<int>,greater<int> >q;
int main(){
read(x),read(y),read(z),n=x+y+z;
for(rg int i=1,u,v,w;i<=n;i++){
read(u),read(v),read(w);
num+=u,v-=u,w-=u;
a[i].x=v,a[i].y=w;
}
sort(a+1,a+n+1,cmp);long long now=0;
for(rg int i=1;i<=z;i++)now+=a[i].y,q.push(a[i].y);
for(rg int i=z+1;i<=n;i++){
sum[i-1]=now,q.push(a[i].y);
now+=a[i].y,now-=q.top();q.pop();
}
sum[n]=now;
while(!q.empty())q.pop();now=0;
for(rg int i=n;i>=n-y+1;i--)now+=a[i].x,q.push(a[i].x);
for(rg int i=n-y;i>=z;i--){
ans=max(ans,now+sum[i]+num),q.push(a[i].x);
now+=a[i].x,now-=q.top();q.pop();
}
printf("%lld\n",ans);
}

AT2672 Coins的更多相关文章

  1. [LeetCode] Arranging Coins 排列硬币

    You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...

  2. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  3. Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)

    传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...

  4. csuoj 1119: Collecting Coins

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1119 1119: Collecting Coins Time Limit: 3 Sec  Memo ...

  5. Coins

    Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hi ...

  6. hdu 1398 Square Coins (母函数)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  7. (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)

    http://poj.org/problem?id=3260   Description Farmer John has gone to town to buy some farm supplies. ...

  8. POJ3260The Fewest Coins[背包]

    The Fewest Coins Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6299   Accepted: 1922 ...

  9. POJ1742 Coins[多重背包可行性]

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 34814   Accepted: 11828 Descripti ...

随机推荐

  1. QWidget、QMainWindow、QFrame、QWindow、QDialog、QScrollArea区别

    QWidget是所有可视化控件的基类,可以直接渲染出一个窗口来. QMainWindow用来表示一个主窗口,这个主窗口可以设置菜单和工具栏 QFrame用来表示一个框架,用来当作容器,因为可以设置它的 ...

  2. eslipse 修改tomcat server location 解决HTTP Status 404 – Not Found

    Eclipse中tomcat service设置选择window ----show view---services可以看到服务的面板双击tomcat进入配置界面Service Locations(Sp ...

  3. tensorflow中常量(constant)、变量(Variable)、占位符(placeholder)和张量类型转换reshape()

    常量 constant tf.constant()函数定义: def constant(value, dtype=None, shape=None, name="Const", v ...

  4. Sqlite表结构读取工具,word批量转html,在线云剪贴板,文件批量提取工具;

    工欲善其事必先利其器,本周为您推荐工具排行 Sqlite表结构读取工具,word批量转html,在线云剪贴板,文件批量提取工具:     本周我们又要发干货了,准备好接受了吗? 为什么是干货,就是因为 ...

  5. How to manage concurrency in Django models

    How to manage concurrency in Django models The days of desktop systems serving single users are long ...

  6. DC/DC尖峰脉冲吸收电路

    在DC/DC转换器中,脉冲问题直接影响到产品的EMI和电源噪声,需要在某些时候加尖峰脉冲吸收电路. 从上图可以看到,尖峰脉冲吸收电路就是一个RC吸收电路.至于在DC/DC哪里加RC吸收电路,这里有一个 ...

  7. HLSL学习笔记(一):基础

    http://www.cnblogs.com/rainstorm/archive/2013/05/04/3057444.html 前言 五一在家无事,于是学习了一下HLSL,基于XAN4.0的.学习完 ...

  8. 洛谷【P1104】生日(选择排序版)

    题目传送门:https://www.luogu.org/problemnew/show/P1104 题目很简单,不过我是来讲选择排序的. 选择排序\((Selection sort)\)是一种简单直观 ...

  9. Centos6.5命令行快捷键

    ctrl+a打开一个新的终端 ctrl+l 清除屏幕内容 ctrl+a 切换到命令行开始ctrl+e 切换到命令行末尾ctrl+u 剪切光标之前的内容ctrl+k 剪切光标之后的内容 Ctrl+-&g ...

  10. java代码JFrame练习

    总结: package com.da; import java.awt.Button; import java.awt.Color; import java.awt.FlowLayout; impor ...