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,并且使得低能耗的电池尽量多

题解:

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

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

代码

  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <ctime>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <set>
  8. #include <vector>
  9. #include <sstream>
  10. #include <queue>
  11. #include <typeinfo>
  12. #include <fstream>
  13. #include <map>
  14. #include <stack>
  15. typedef long long ll;
  16. using namespace std;
  17. //freopen("D.in","r",stdin);
  18. //freopen("D.out","w",stdout);
  19. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  20. #define test freopen("test.txt","r",stdin)
  21. const int maxn=;
  22. #define mod 1000000007
  23. #define eps 1e-9
  24. const int inf=0x3f3f3f3f;
  25. const ll infll = 0x3f3f3f3f3f3f3f3fLL;
  26. inline ll read()
  27. {
  28. ll x=,f=;char ch=getchar();
  29. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  30. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  31. return x*f;
  32. }
  33. //**************************************************************************************
  34.  
  35. struct node
  36. {
  37. ll x,y,z;
  38. };
  39. bool cmp(node a,node b)
  40. {
  41. return a.x>b.x;
  42. }
  43. bool cmp1(node a,node b)
  44. {
  45. if(a.y==b.y)
  46. return a.x>b.x;
  47. return a.y>b.y;
  48. }
  49. node a[maxn];
  50. ll sum1[maxn];
  51. ll sum2[maxn];
  52. int main()
  53. {
  54. int n=read();
  55. ll m=read();
  56. for(int i=;i<=n;i++)
  57. a[i].x=read(),a[i].y=read(),a[i].z=i;
  58. sort(a+,a+n+,cmp);
  59. ll sum=;
  60. int num=;
  61. for(int i=;i<=n;i++)
  62. {
  63. num=i;
  64. sum+=a[i].x;
  65. if(sum>=m)
  66. break;
  67. }
  68. sort(a+,a+n+,cmp1);
  69. int flag=;
  70. for(int i=;i<=n;i++)
  71. if(a[i].y!=)
  72. {
  73. flag=i;
  74. break;
  75. }
  76. int num1=,num2=;
  77. if(flag==)
  78. flag=n+;
  79. for(int i=;i<flag;i++)
  80. {
  81. sum1[num1]=sum1[num1-]+a[i].x;
  82. num1++;
  83. }
  84. for(int i=flag;i<=n;i++)
  85. {
  86. sum2[num2]=sum2[num2-]+a[i].x;
  87. num2++;
  88. }
  89. for(int i=num;i>=;i--)
  90. {
  91. if(sum1[i]+sum2[num-i]>=m)
  92. {
  93. cout<<num<<" "<<i<<endl;
  94. for(int j=;j<=i;j++)
  95. cout<<a[j].z<<" ";
  96. for(int j=flag;j<flag+num-i;j++)
  97. cout<<a[j].z<<" ";
  98. cout<<endl;
  99. return ;
  100. }
  101. }
  102. }

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. 解决Jsoup网页抓取过程中需要cookie的问题

    最近在做城觅网的信息抓取,发现城觅网上海与北京的url是一样的.那怎样才确定信息的来源呢?折腾了半天,才发现城觅网是使用cookie的,如果你把网站的cookie禁用了,就无法在上海与北京之间切换了. ...

  2. 五分钟solr4.5教程(搭建、运行)

    环境要求 jdk1.6及以上版本 solr发布版本 下载地址 http://lucene.apache.org/solr/mirrors-solr-latest-redir.html? 启动solr ...

  3. Visual Studio 2010中创建ASP.Net Web Service

    转自:http://blog.csdn.net/xinyaping/article/details/7331375 很多人在论坛里说,在Visual Studio 2010中不能创建“ASP.Net ...

  4. 擦亮自己的眼睛去看SQLServer之简单Select(转)

    摘要:这篇文章主要和大家讨论几乎所有人都熟悉,但不少人又陌生的一条select语句. 这篇文章主要和大家讨论几乎所有人都熟悉,但不少人又陌生的一条select语句.不知道大家有没有想过到底是什么东西让 ...

  5. Cloudera的安装

    To enable these parts of the tutorial, choose one of the following options: To use Cloudera Express ...

  6. Activity的活动周期

    Android 使用task来管理Activity.是一个栈的形式.遵循后进先出原则. Activity的四种状态: 运行状态(用户可以操作该Activity).暂停状态(用户可见该Activity, ...

  7. 【和我一起学python吧】Python解释执行原理

    这里的解释执行是相对于编译执行而言的.我们都知道,使用C/C++之类的编译性语言编写的程序,是需要从源文件转换成计算机使用的机器语言,经过链接器链接之后形成了二进制的可执行文件.运行该程序的时候,就可 ...

  8. [LeetCode] Add Digits (a New question added)

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

  9. ESXI安装

    1.设置从USB启动 按DEL进入BIOS设置 参考http://www.upanok.com/jiaocheng/68.html 先插入USB,在选择ADVANCAED BIOS FEATURES ...

  10. FLEX实现两侧边栏固定中间自适应布局

    <style type="text/css"> #outer{ display: flex; width: 100%; flex-flow: row nowrap; } ...