###### CF 3B Lorry

sort + greedy

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAX = 1e5 + 1000;

struct bb
{
int t,p,num;
} kay[MAX],aca[MAX];
int cmp(const bb & a,const bb & b)
{
return a.p > b.p;
}
int n,v,num[MAX],sum_num;
int main()
{
while(~scanf("%d%d",&n,&v))
{
int t,p;
int num_kay = 0,num_aca = 0;
for(int i = 0; i < n; i ++)
{
scanf("%d%d",&t,&p);
if(t%2 == 0)
{
aca[num_aca].t = t;
aca[num_aca].p = p;
aca[num_aca].num = i + 1;
num_aca ++;
}
else
{
kay[num_kay].t = t;
kay[num_kay].p = p;
kay[num_kay].num = i + 1;
num_kay ++;
}
}
sort(kay,kay+num_kay,cmp);
sort(aca,aca+num_aca,cmp);
LL sum1[MAX],sum2[MAX];
sum1[0] = 0;
sum2[0] = 0;
for(int i = 1; i <= num_kay; i ++)
sum1[i] = sum1[i-1] + (LL)kay[i-1].p;
for(int i = 1; i <= num_aca; i ++)
sum2[i] = sum2[i-1] + (LL)aca[i-1].p;

int h1 = 0,h2 = 0,p1,p2;
LL ans = 0,sum = 0;
for(int i = 0; i <= num_kay; i ++)
{
if(i > v) break;
int rest = v - i;
if(rest >= num_aca*2) p2 = num_aca;
else p2 = rest /2;
sum = sum1[i] + sum2[p2];
if(sum > ans)
{
ans = sum;
h1 = i;
h2 = p2;
}
}
cout<<ans<<endl;
sum_num = 0;
for(int i = 0;i < h2;i ++)
{
num[sum_num ++] = aca[i].num;
}
for(int i = 0;i < h1;i ++)
{
num[sum_num ++] = kay[i].num;
}
sort(num,num+sum_num);
for(int i = 0;i < sum_num;i ++)
cout<<num[i]<<" ";
cout<<endl;

}
return 0;
}
/**
3 2
1 2
2 7
1 3
sum1  3 2
sum2  7
4 3
1 4
2 6
1 1
1 1.
sum1 4 1 1
sum2 6
2 2
1 4
2 6
sum1 4
sum2 6
*/


#### Cloud Foundry技术新纪元 2017年发展趋势前瞻

2017年03月13日 13:30

#### CF_3B_Lorry

2016-03-23 22:03:26

#### codeforces 3B Lorry

2014-03-28 12:29:04

#### CodeForce 3B Lorry（贪心）

2014-10-16 20:16:06

#### Codeforces 3B Lorry 贪心

2013-08-20 14:13:07

#### codeforce 3B. Lorry（贪心）

2015-07-11 19:48:46

#### CodeForces 3-B Lorry

2015-08-10 08:35:41

#### codeforces 3B (贪心)

2015-03-30 22:25:57

#### [CF 3B]Lorry[Greedy]

2013-08-06 15:54:28

#### Codeforces 3 B. Lorry 暴力 排序 枚举 贪心

2014-10-18 09:03:20

CF 3B Lorry