【题目描述】
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It’s known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times bigger than kayaks (and occupy the space of 2 cubic metres).

Each waterborne vehicle has a particular carrying capacity, and it should be noted that waterborne vehicles that look the same can have different carrying capacities. Knowing the truck body volume and the list of waterborne vehicles in the boat depot (for each one its type and carrying capacity are known), find out such set of vehicles that can be taken in the lorry, and that has the maximum total carrying capacity. The truck body volume of the lorry can be used effectively, that is to say you can always put into the lorry a waterborne vehicle that occupies the space not exceeding the free space left in the truck body.

【输入】
The first line contains a pair of integer numbers n and v (1 ≤ n ≤ 105; 1 ≤ v ≤ 109), where n is the number of waterborne vehicles in the boat depot, and v is the truck body volume of the lorry in cubic metres. The following n lines contain the information about the waterborne vehicles, that is a pair of numbers ti, pi (1 ≤ ti ≤ 2; 1 ≤ pi ≤ 104), where ti is the vehicle type (1 – a kayak, 2 – a catamaran), and pi is its carrying capacity. The waterborne vehicles are enumerated in order of their appearance in the input file.

【输出】
In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them.

【样例输入】
3 2
1 2
2 7
1 3

【样例输出】
7
2

题目链接:https://codeforces.com/contest/3/problem/B

代码如下:

#include <bits/stdc++.h>
using namespace std;
static const int MAXN=100000;
struct Node{int t,p,num;friend bool operator < (Node p,Node q){return p.p<q.p;}
}boat[MAXN+10];
int main()
{std::ios::sync_with_stdio(false);std::cin.tie(0),cout.tie(0);int n,v;cin>>n>>v;priority_queue<Node> Q1;priority_queue<Node> Q2;for(int i=1;i<=n;i++){cin>>boat[i].t>>boat[i].p;boat[i].num=i;if(boat[i].t==1) Q1.push(boat[i]);else Q2.push(boat[i]);}int sum=0;queue<Node> Q;while(v>0){if(v==1)while(!Q2.empty())Q2.pop();if(Q1.empty() && Q2.empty())break;else if(Q1.empty()){if(v==1) break;else{Q.push(Q2.top());sum+=Q2.top().p;Q2.pop();v-=2;}}else if(Q2.empty()){Q.push(Q1.top());sum+=Q1.top().p;Q1.pop();v--;}else if(Q1.size()==1){if((v&1) || Q1.top().p>=Q2.top().p){Q.push(Q1.top());sum+=Q1.top().p;Q1.pop();v--;}else{Q.push(Q2.top());sum+=Q2.top().p;Q2.pop();v-=2;}}else{Node temp=Q1.top();Q1.pop();if((v&1) || temp.p>=Q2.top().p){Q.push(temp);sum+=temp.p;v--;}else if(temp.p+Q1.top().p>Q2.top().p){Q.push(temp);Q.push(Q1.top());sum+=temp.p+Q1.top().p;Q1.pop();v-=2;}else{Q.push(Q2.top());sum+=Q2.top().p;Q2.pop();Q1.push(temp);v-=2;}}}cout<<sum<<endl;while(!Q.empty()){cout<<Q.front().num<<" ";Q.pop();}cout<<endl;return 0;
}

CodeForces - 3B Lorry【贪心】相关推荐

  1. CodeForces 3B Lorry 贪心

    题目大意是有体积为v的背包,有体积为1和2的两种物品若干,这些物品都有各自的价值.求如何取这些物品可使背包中物品的价值最大. 开始一看到是背包就傻眼了==因为数据量太大1 ≤ n ≤ 105; 1 ≤ ...

  2. codeforce 3B lorry (贪心)

    有货车运量V: 有若干物品A 占2单位体积,有若干物品B占1单位体积: 相同种类的物品价值不一定一样: 序号按照输入顺序而定: 问货车可以拉走最多多少价值的物品,并输出所选物品的序号: 思路:贪心,先 ...

  3. CodeForces 3-B Lorry

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...

  4. CF 3B. Lorry

    CF 3B. Lorry   点击打开链接 题意:有体积为1或2的物品共n种 你的容量为m,求你最多可以拿到多少价值的物品. 思路:贪心的思维 再加上尺取法求得最大的价值,这是我看大佬的博客才写出来的 ...

  5. codeforce 3B. Lorry(贪心)

    题目:http://codeforces.com/problemset/problem/3/B 大意是,给定N和V,在给出N个vehicle的类型号(1或2)和各自的载重量,求在不超过V的情况下最大的 ...

  6. Codeforces1600数学day5[找规律CodeForces - 1059C,贪心数学A - Banh-mi CodeForces - 1062C ]

    A - Banh-mi CodeForces - 1062C 题目大意:就是开始给你一个01序列,和q次询问,每次询问会给你一个区间,每次你会从这个区间内拿出一个数,在区间内的其他未被拿走的数字会加上 ...

  7. CodeForces - 1494D Dogeforces(贪心+构造)

    题目链接:点击查看 题目大意:给出 nnn 个叶子结点和一个 n∗nn*nn∗n 的 LCALCALCA 矩阵,其中 LCALCALCA 表示的是最近公共祖先节点的权值,现在需要构造出一棵自顶向下权值 ...

  8. 【CF】3B Lorry

    这道题目网上有几个题解,均有问题.其实就是简单的贪心+排序,没必要做的那么复杂. 一旦tot+curv > v时,显然curv==2, 有三种可能: (1)取出最小的curv==1的pp,装入当 ...

  9. Codeforces 1203E Boxers(贪心)

    题目链接:https://codeforces.com/problemset/problem/1203/E 题意:给定n个数字,每个数字可以进行一次+1或是-1的变换(也可以不变),问通过对部分数字适 ...

  10. codeforces数学1600day4[贪心数学公式推导CodeForces - 1151D ,思维CodeForces - 1085C,数论同余+组合计数 CodeForces - 1056B]

    A - Stas and the Queue at the Buffet CodeForces - 1151D 题目大意:就是给你n个人在排队,每个人都有一个ai值和bi值,每个人的不满意度就是f(i ...

最新文章

  1. 那些按烂的Linux命令集合贴
  2. C++ 学习路线推荐
  3. visjs使用小记-1.创建一个简单的网络拓扑图
  4. Shell脚本函数(函数传参、递归、创建库)
  5. 常用事务代码 sap_SAP_PS_事务代码
  6. java mysql 异步查询数据库_java 异步操作数据库
  7. LintCode 1862. 给树浇水的时间(图的遍历)
  8. 蘑菇街更新招股书:Q3亏1.8亿 IPO后陈琪有79%投票权
  9. vue动态发布到线上_Vue 2.6 发布了
  10. Flutter拓展 一步一步教你安装Flutter(最火的移动框架)
  11. 【MINI2440】linux系统下载全流程
  12. Python 爬虫 目标:千图网VIP高清无水印下载即用
  13. 伦敦大学国王学院金融数学理学硕士研究生offer一枚
  14. 【房屋租赁网管理系统】
  15. FastTunnel - 免费好用的内网穿透工具搭建教程
  16. Easyui后台管理界面设计
  17. [论文阅读] Structure-Consistent Weakly Supervised Salient Object Detection with Local Saliency Coherence
  18. 1421. 净现值查询
  19. 关于制定《传统蒙古文信息交换与处理字形字符标准编码》
  20. 华为 进入和退出Fastboot、eRecovery和Recovery升级模式

热门文章

  1. mysql select 临时表_mysql临时表的产生
  2. 境外显示手机无服务器,手机卡在国外无服务怎么办
  3. 设计模式——工厂方法模式
  4. 成功之路散文连载之笨人论
  5. 惊爆:普通人也能监听你MSN聊天(转)
  6. oeasy教您玩转vim - 28 - 水平移动
  7. hdu6070 Dirt Ratio(二分+线段树)
  8. access使用相对路径
  9. 如何快速撰写/总结国内外研究现状?
  10. 大学里大四的学生一般在干什么