# 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
*/


• 本文已收录于以下专栏：

## codeforces 3B Lorry

B. Lorry time limit per test 2 seconds memory limit per test 64 megabytes input standard input...
• ahoLic
• 2014年03月28日 12:29
• 2144

## codeforces 3B. Lorry

• ymrfzr
• 2013年05月29日 21:13
• 695

## Codeforces 3B. Lorry

B. Lorry time limit per test 2 seconds memory limit per test 64 megabytes input standard input...

## Codeforces 3B Lorry

EnglishDescA group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to t...

## CF - 805B. 3-palindrome - 贪心+构造

1.题目描述： B. 3-palindrome time limit per test 1 second memory limit per test 256 mega...

## CF3 A + B

A - Vladik and Courtesy   At regular competition Vladik and Valera won a and b candies respectively...

举报原因： 您举报文章：CF 3B Lorry 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)