Codeforces Gym 100513D D. Data Center 前缀和 排序
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 ai, li (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 前缀和 排序的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces 950.E Data Center Maintenance
E. Data Center Maintenance time limit per test 1 second memory limit per test 512 megabytes input st ...
- 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 ...
- 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 ...
- CodeForces 816B Karen and Coffee(前缀和,大量查询)
CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the ...
- Data Center手册(4):设计
基础架构 拓扑图 Switching Path L3 routing at aggregation layer L2 switching at access layer L3 switch融合了三种功 ...
- Data Center手册(2): 安全性
有个安全性有下面几种概念: Threat:威胁 Vulnerability: 安全隐患 Attack: 攻击 有关Threat 常见的威胁有下面几种 DoS(Denial of Service拒绝服务 ...
随机推荐
- 【DFS】NYOJ-82 迷宫寻宝(一)-条件迷宫问题
[题目链接:NYOJ-82] #include<iostream> #include<cstring> using namespace std; struct node{ in ...
- 【原】cocos2d-x 2.0.4 不支持https协议 CURLE_UNSUPPORTED_PROTOCOL
我们项目组用的cocos2d-x版本还比较老,各种好的功能不能用. 今天就让我遇到一个问题,使用CCHttpClient发送http请求的时候,https协议的不支持,返回失败信息如下 errorco ...
- 为SQL表添加全文索引范例
--范例: --为HR_Job中的JobTitle,JobDes创建全文索引 execute sp_fulltext_catalog 'boli188', 'create' --创建全文目录,boli ...
- 连接Excel文件时,未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序
问题与解决 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序 错误. string strCon = " Provider = Microsoft.Jet.OL ...
- visual studio 2013 配置 ef+pgsql
环境:VS2013,WIN7 准备工作: 1.有哪些供应商提供EF6的支持? 可以看msdn给出的答案:Which providers are available for EF6? 在本文使用 Dev ...
- Python--类使用
类使用的几个注意点: 1. 类的语法结构:2. __init__(self),3. __metaclass__=type, (新式类)4. super(subclassname, self).__in ...
- 理解CSS盒子模型
概述 网页设计中常听的属性名:内容(content).填充(padding).边框(border).边界(margin),CSS盒子模型都具备这些属性,也主要是这些属性. 这些属性我们可以把它转移到我 ...
- XAMPP:访问phpmyadmin出错的解决方案
来源:http://www.ido321.com/1246.html XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的建 XAMPP 软件站集成软件包,轻巧,用起来很方便.它提 ...
- Android多媒体--MediaCodec的实例化方法
*由于作者水平限制,文中难免有错误和不恰当之处,望批评指正. *转载请注明出处:http://www.cnblogs.com/roger-yu/ MediaCodec的实例化方法主要有两种: 1.使用 ...
- Components of the Impala Server
Components of the Impala Server The Impala server is a distributed, massively parallel processing (M ...