#include <bits/stdc++.h>
using namespace std;
template<typename... Args>void print(Args... args){int write[] = {(cout << args, 0)...};}
struct dx
{
int t, val, id;
};
bool cmp1(dx a, dx b)
{
return a.val > b.val;
}
vector<int> k;
vector<dx> a, b;
int n, v, t, val, sum = 0, ttt = 0, all = 0;
dx a1, a2, bb;
int main()
{
cin >> n >> v;
for(int i = 1; i <= n; i++)
{
cin >> t >> val;
all += t;
if(t == 1)
{
a.push_back({t, i, val});
}
else
{
b.push_back({t, i, val});
}
}
sort(a.begin(), a.end(), cmp1);
sort(b.begin(), b.end(), cmp1);
while(1)
{
if((a.empty() && ttt + 1 == all) || ttt == all) break;
a1 = a[0];
a2 = a[1];
bb = b[0];
if(a1.val + a2.val >= bb.val)
{
print(a1.val, " ", a2.val, "\n");
sum += a1.val + a2.val;
ttt += a1.t + a2.t;
a.erase(a.begin());
a.erase(a.begin());
k.push_back(a1.id);
k.push_back(a2.id);
}
else
{
print(bb.val, "\n");
sum += bb.val;
ttt += bb.t;
b.erase(b.begin());
k.push_back(bb.id);
}
}
sort(k.begin(), k.end());
cout << sum << endl;
for(int i = 0; i < k.size(); i++)
{
cout << k[i] << " ";
}
cout << endl;
return 0;
}
思路是模拟,但是不知道为啥RE(3221226356)