D. Data Center

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/560/problem/B

Description

The startup "Booble" has shown explosive growth and now it needs a new data center with the capacity of m petabytes. Booble can buy servers, there are n servers available for purchase: they have equal price but different capacities. The i-th server can store ai petabytes of data. Also they have different energy consumption — some servers are low voltage and other servers are not.

Booble wants to buy the minimum number of servers with the total capacity of at least m petabytes. If there are many ways to do it Booble wants to choose a way to maximize the number of low voltage servers. Booble doesn't care about exact total capacity, the only requirement is to make it at least m petabytes.

Input

The first line contains two integer numbers n and m (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 2·1015) — the number of servers and the required total capacity.

The following n lines describe the servers, one server per line. The i-th line contains two integers aili (1 ≤ ai ≤ 1010, 0 ≤ li ≤ 1), where ai is the capacity, li = 1 if server is low voltage and li = 0 in the opposite case.

It is guaranteed that the sum of all ai is at least m

Output

Print two integers r and w on the first line — the minimum number of servers needed to satisfy the capacity requirement and maximum number of low voltage servers that can be bought in an optimal r servers set.

Print on the second line r distinct integers between 1 and n — the indices of servers to buy. You may print the indices in any order. If there are many solutions, print any of them.

Sample Input

4 10
3 1
7 0
5 1
4 1

Sample Output

2 1
4 2

HINT

题意

有个人要买电池,要求买尽量少的电池,使得满足容量大于等于m,并且使得低能耗的电池尽量多

题解:

先排个序,判断出得至少买多少个电池

然后开始暴力枚举低能耗的电池个数,肯定优先拿电量大的,然后扫一遍就好了

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** struct node
{
ll x,y,z;
};
bool cmp(node a,node b)
{
return a.x>b.x;
}
bool cmp1(node a,node b)
{
if(a.y==b.y)
return a.x>b.x;
return a.y>b.y;
}
node a[maxn];
ll sum1[maxn];
ll sum2[maxn];
int main()
{
int n=read();
ll m=read();
for(int i=;i<=n;i++)
a[i].x=read(),a[i].y=read(),a[i].z=i;
sort(a+,a+n+,cmp);
ll sum=;
int num=;
for(int i=;i<=n;i++)
{
num=i;
sum+=a[i].x;
if(sum>=m)
break;
}
sort(a+,a+n+,cmp1);
int flag=;
for(int i=;i<=n;i++)
if(a[i].y!=)
{
flag=i;
break;
}
int num1=,num2=;
if(flag==)
flag=n+;
for(int i=;i<flag;i++)
{
sum1[num1]=sum1[num1-]+a[i].x;
num1++;
}
for(int i=flag;i<=n;i++)
{
sum2[num2]=sum2[num2-]+a[i].x;
num2++;
}
for(int i=num;i>=;i--)
{
if(sum1[i]+sum2[num-i]>=m)
{
cout<<num<<" "<<i<<endl;
for(int j=;j<=i;j++)
cout<<a[j].z<<" ";
for(int j=flag;j<flag+num-i;j++)
cout<<a[j].z<<" ";
cout<<endl;
return ;
}
}
}

Codeforces Gym 100513D D. Data Center 前缀和 排序的更多相关文章

  1. Codeforces Gym 100637A A. Nano alarm-clocks 前缀和处理

    A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/p ...

  2. Codeforces Gym 100637A A. Nano alarm-clocks 前缀和

    A. Nano alarm-clocks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/p ...

  3. Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路

    Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xx ...

  4. Codeforces 950.E Data Center Maintenance

    E. Data Center Maintenance time limit per test 1 second memory limit per test 512 megabytes input st ...

  5. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  6. Codeforces Gym H. Hell on the Markets 贪心

    Problem H. Hell on the MarketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vj ...

  7. CodeForces 816B Karen and Coffee(前缀和,大量查询)

    CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the ...

  8. Data Center手册(4):设计

    基础架构 拓扑图 Switching Path L3 routing at aggregation layer L2 switching at access layer L3 switch融合了三种功 ...

  9. Data Center手册(2): 安全性

    有个安全性有下面几种概念: Threat:威胁 Vulnerability: 安全隐患 Attack: 攻击 有关Threat 常见的威胁有下面几种 DoS(Denial of Service拒绝服务 ...

随机推荐

  1. 【转】VS2012编译出来的程序,在XP上运行,出现“.exe 不是有效的 win32 应用程序” “not a valid win32 application”

    原文网址:http://www.cnblogs.com/Dageking/archive/2013/05/15/3079394.html VS2012编译出来的程序,在XP上运行,出现“.exe 不是 ...

  2. 通过js检测到iframe,使父窗口重定向到index -----------???----------------------

    通过js检测到iframe,使父窗口重定向到index -----------???---------------------- 如果本身已将在iframe中,那么重定向的页面应该直接添加到父级ifr ...

  3. Python抓取单个网页中所有的PDF文档

    Github博文地址,此处更新可能不是很及时. 1.背景 最近发现算法以及数据结构落下了不少(其实还是大学没怎么好好学,囧rz),考虑到最近的项目结构越来越复杂了,用它来练练思路,就打算复习下数据结构 ...

  4. java web 学习十六(JSP指令)

    一.JSP指令简介 JSP指令(directive)是为JSP引擎而设计的,它们并不直接产生任何可见输出,而只是告诉引擎如何处理JSP页面中的其余部分. 在JSP 2.0规范中共定义了三个指令: pa ...

  5. 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?

    UVa11991 Easy Problem from Rujia Liu?  思路:  构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...

  6. 在Ubuntu6.06 在搭建SVN服务器及在windows建立svn+ssh客户端

    部门现在使用的Linux系统是Ubuntu6.06,内核版本为2.6.15-57-386.由于系统比较老,所有用网上介绍的方法搭建SVN服务器经常出错,所以参考文章[1],将自己的搭建过程记录下. 1 ...

  7. Tkinter教程之Button篇(1)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811298 #Tkinter教程之Button篇(1)#Button功能触发事件'''1.一个 ...

  8. 基于Hbase数据的Mapreduce程序环境开发

    一.实验目标 编写Mapreduce程序,以Hbase表数据为Map输入源,计算结果输出到HDFS或者Hbase表中. 在非CDH5的Hadoop集群环境中,将编写好的Mapreduce程序整个工程打 ...

  9. vim对erlang语法支持

    发现vim写erlang代码语法缩进都不对,后来发现vim是7.0的,vim7.3开始才对erlang这块进行了支持,所以升级vim git上下载源码包,然后一系列配置安装 http://www.2c ...

  10. redis.conf的配置

    daemonize yes   :  redis server 实例是否以后台方式运行 , no:不以后台方式运行(默认) , yes:以后台方式运行. requirepass 密码 :  密码最好长 ...