CoderForces-913D
You are preparing for an exam on scheduling theory. The exam will last for exactly Tmilliseconds and will consist of n problems. You can either solve problem i in exactly ti milliseconds or ignore it and spend no time. You don't need time to rest after solving a problem, either.
Unfortunately, your teacher considers some of the problems too easy for you. Thus, he assigned an integer ai to every problem i meaning that the problem i can bring you a point to the final score only in case you have solved no more than ai problems overall (including problem i).
Formally, suppose you solve problems p1, p2, ..., pk during the exam. Then, your final score s will be equal to the number of values of j between 1 and k such that k ≤ apj.
You have guessed that the real first problem of the exam is already in front of you. Therefore, you want to choose a set of problems to solve during the exam maximizing your final score in advance. Don't forget that the exam is limited in time, and you must have enough time to solve all chosen problems. If there exist different sets of problems leading to the maximum final score, any of them will do.
Input
The first line contains two integers n and T (1 ≤ n ≤ 2·105; 1 ≤ T ≤ 109) — the number of problems in the exam and the length of the exam in milliseconds, respectively.
Each of the next n lines contains two integers ai and ti (1 ≤ ai ≤ n; 1 ≤ ti ≤ 104). The problems are numbered from 1 to n.
Output
In the first line, output a single integer s — your maximum possible final score.
In the second line, output a single integer k (0 ≤ k ≤ n) — the number of problems you should solve.
In the third line, output k distinct integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the indexes of problems you should solve, in any order.
If there are several optimal sets of problems, you may output any of them.
Example
5 300
3 100
4 150
4 80
2 90
2 300
2
3
3 1 4
2 100
1 787
2 788
0
0
2 100
2 42
2 58
2
2
1 2
Note
In the first example, you should solve problems 3, 1, and 4. In this case you'll spend 80 + 100 + 90 = 270 milliseconds, falling within the length of the exam, 300 milliseconds (and even leaving yourself 30 milliseconds to have a rest). Problems 3 and 1 will bring you a point each, while problem 4 won't. You'll score two points.
In the second example, the length of the exam is catastrophically not enough to solve even a single problem.
In the third example, you have just enough time to solve both problems in 42 + 58 = 100milliseconds and hand your solutions to the teacher with a smile.
题解:
通过优先队列每次把所有分数为i的元素按照时间从大到下出队列知道队列中只剩下i个元素为止,如果当前SumTime<t && pq.size()==i,则当前解为最优解,。
AC代码为:
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn=2e5+; struct node{
int lie;
int ai;
int time;
} stu[maxn]; bool cmp(node a,node b)
{
return a.time < b.time ;
} struct comp{
bool operator()(const node a,const node b)
{
if(a.ai!=b.ai)
return a.ai>b.ai;
return a.time<b.time;
}
}; priority_queue<node,vector<node>,comp> pq; int main()
{
int n,T,cnt=;
cin>>n>>T;
for(int i=;i<n;i++)
{
cin>>stu[i].ai>>stu[i].time;
stu[i].lie=i+;
} sort(stu,stu+n,cmp); for(int i=;i<n;i++)
{
if(stu[i].time > T)
break;
if(stu[i].ai>cnt)
{
T-=stu[i].time;
pq.push(stu[i]);
cnt++;
} while(!pq.empty() && pq.top().ai<cnt)
{
cnt--;
T+=pq.top().time;
pq.pop();
} } cout<<cnt<<endl;
cout<<cnt<<endl; while(!pq.empty())
{
cout<<pq.top().lie<<" ";
pq.pop();
}
cout<<endl; return ;
}
CoderForces-913D的更多相关文章
- Codeforces 913D - Too Easy Problems
913D - Too Easy Problems 思路:二分check k 代码: #include<bits/stdc++.h> using namespace std; #define ...
- coderforces #387 Servers(模拟)
Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- coderforces #384 D Chloe and pleasant prizes(DP)
Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- coderforces 731c
题目大意:给出m组数据,每组数据包括两个数Li与Ri,分别表示左右袜子的索引(下标),表示这一天要穿的袜子:而我们要使得每天穿的这两只袜子的颜色相同,所以可以改变袜子的颜色,每次只能改变一只袜子的颜色 ...
- coderforces 721b
题目描述: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- CoderForces 280B(记忆化搜索)
题目大意:一个纸牌游戏,52张纸牌排成一列,每张纸牌有面值和花色两种属性.每次操作可以用最后一张纸牌将倒数第二张或者倒数第四张替换,但前提是两张牌的花色或者面值相同.问最终能否只剩一张牌. 题目分析: ...
- CoderForces 689A Mike and Cellphone (水题)
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...
- CoderForces 518C Anya and Smartphone (模拟)
题意:给定一个手机,然后一共有 n 个app,告诉你每个屏幕最多放 k 个,现在要你运行 m 个app,每次都从第一个屏幕开始滑动,每运行一个,它就和前一个交换位置,第一个就不换了,现在问你要滑动多少 ...
- CoderForces 518D Ilya and Escalator (期望DP)
题意:给定 n 个人,在每一时刻一个人进入地铁的概率是 p,站着不动的概率是 1-p,然后问你 t 时间地铁里有多少人. 析:很明显这是一个期望DP,用d[i][j]表示 i 时刻 j 个人进入地铁的 ...
- CoderForces 687C The Values You Can Make (01背包,DP)
题意:给定 n 个硬币和一个值 k,问你在用一些硬币组成面值为 k的这些硬币还能组成多少种其他面值. 析:如果这样说,由这些硬币能组成多少种不同的面值,那么是不是就很熟悉了,这不就是01背包么,这个题 ...
随机推荐
- SpringBoot 2.x版本+MultipartFile设置指定文件上传大小
SpringBoot-versio:2.1.9-RELEASE 由于新版本的SpringBoot已经弃用了如下, 这种方式,提供了新的 配置方案. 这个是官方的介绍 Handling Multipar ...
- 生信 - 从repeatmasker传送门过来的 blast
以前有的是非完整时间写的博客,抽时间需要统一整理一下. 今天在重新装repeatmasker. 整个过程是这样的,有关联的事情有两个. 1. 装repeatmasker需要各种Prerequisite ...
- 关于laravel框架Model返回的值为stdClass对象转换两种方法
一般情况下laravel模型层查询出来的数据是stdClass对象,无法直接当做数组进行视图展示,所以需要转换为数组格式. Model中查到的数据为 $data ,对它进行转化,转化为数组. 第一 ...
- 用IDEA导入Eclipse的JavaWEB项目
1.File----Open 2.选择项目路径 点击OK,这时候会弹出一个窗口,让你选择本窗口打开项目还是新建一个窗口,这个随意. 3.添加WEB框架 4.添加各种自己需要的jar包 5.添加Tomc ...
- Linux菜鸟——常见命令一 权限
Linux对文件和目录的权限位 权限位是十位 第一位 代表文件类型 - 普通文件 d 目录文件 l 链接文件 后面九尾 所有者权限 u = user 所属组权限 g = group 其他人权限 o = ...
- zabbix 发送报警邮件
- pycharm的安装流程
以windows版本举例: 1.首先去Pycharm官网,或者直接输入网址:http://www.jetbrains.com/pycharm/download/#section=windows,下载P ...
- 关于C# 语言
C# 语法高度重视表达,但学习起来也很简单轻松. 任何熟悉 C.C++ 或 Java 的人都可以立即认出 C# 的大括号语法. 通常情况下,了解上述任何一种语言的开发者可以在很短的时间内就开始使用 C ...
- 新闻实时分析系统 大数据Web可视化分析系统开发
1.基于业务需求的WEB系统设计 2.下载Tomcat并创建Web工程并配置相关服务 下载tomcat,解压并启动tomcat服务. 1)新建web app项目 创建好之后的效果 2)对tomcat进 ...
- Fortran文件读写--xdd
1.常规读写 program FileWriteRead implicit none open(unit=,file="F:\desktop\File.txt") !open(un ...