比较排序
作者:
hayate
,
2024-07-09 17:41:46
,
所有人可见
,
阅读 16
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define x first
#define y second
typedef pair<int, int> PII;
const int N = 1e3 + 10;
int n, b;
PII p[N];
int a[N];
bool cmp(PII a, PII b)
{
return a.x + a.y < b.x + b.y;
}
int main()
{
cin >> n >> b;
for(int i = 0; i < n; i ++ )
{
cin >> p[i].x >> p[i].y;
}
sort(p, p + n, cmp);
int sum = 0;
for(int i = 0; i < n; i ++ )
{
if(b >= p[i].x + p[i].y)
{
b = b - p[i].x - p[i].y;
sum ++;
}
else if(b >= p[i].x / 2 + p[i].y)
{
b = b - p[i].x - p[i].y;
sum ++;
}
else
{
break;
}
}
cout << sum << endl;
return 0;
}