Codeforces Gym 100513D D. Data Center Prefixes and sorting

Source: Internet
Author: User

Time Limit:20 Sec

Memory limit:256 MB

Topic Connection

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

Description

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

Booble wants to buy the minimum number of servers with the total capacity of at least M petabytes. If There is many ways to does it booble wants to choose a-to-maximize the number of low voltage servers. Booble doesn ' t care on exact total capacity, the only requirement was to make it at least M petabytes.

Input

The first line contains the numbers n and m (1≤ n ≤2 105, 1≤ m ≤2 10)-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 II Integers  a Span class= "Lower-index" > i ,   l i    (1≤ a i ≤1010, 0≤ l i ≤ 1), Where  a i  is the Capacity,  l I = 1 if server Is low voltage and  l i = 0 in the opposite case.

It is guaranteed, the sum of all ai am at least m

Output

Print integers R and W on the first line-the Minimum number of servers needed to SATISF Y the capacity requirement and maximum number of low voltage servers so 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 could print the indices in any order. If There is 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

Test instructions

There is a person to buy batteries, ask to buy as few batteries as possible, so that the capacity is greater than or equal to M, and so that low energy consumption of batteries as much as possible

Exercises

First order, determine how many batteries to buy at least

And then start to brute force enumerate the number of low-energy batteries, must first take the power of the big, and then sweep it all over again.

Code

#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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineTest Freopen ("Test.txt", "R", stdin)Const intmaxn=202501;#defineMoD 1000000007#defineEPS 1e-9Const intinf=0x3f3f3f3f;Constll infll =0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************structnode{ll x, Y, z;};BOOLCMP (node A,node b) {returnA.x>b.x;}BOOLCMP1 (node A,node b) {if(a.y==b.y)returnA.x>b.x; returnA.y>B.y;} Node A[maxn];ll sum1[maxn];ll SUM2[MAXN];intMain () {intn=read (); ll M=read ();  for(intI=1; i<=n;i++) a[i].x=read (), A[i].y=read (), a[i].z=i; Sort (a+1, a+n+1, CMP); ll Sum=0; intnum=0;  for(intI=1; i<=n;i++) {num=i; Sum+=a[i].x; if(sum>=m) Break; } sort (A+1, a+n+1, CMP1); intflag=0;  for(intI=1; i<=n;i++)        if(a[i].y!=1) {flag=i;  Break; }    intnum1=1, num2=1; if(flag==0) Flag=n+1;  for(intI=1; i<flag;i++) {SUM1[NUM1]=sum1[num1-1]+a[i].x; NUM1++; }     for(inti=flag;i<=n;i++) {sum2[num2]=sum2[num2-1]+a[i].x; Num2++; }     for(inti=num;i>=0; i--)    {        if(sum1[i]+sum2[num-i]>=m) {cout<<num<<" "<<i<<Endl;  for(intj=1; j<=i;j++) cout<<a[j].z<<" ";  for(intj=flag;j<flag+num-i;j++) cout<<a[j].z<<" "; cout<<Endl; return 0; }    }}

Codeforces Gym 100513D D. Data Center Prefixes and sorting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.