AcWing 2040. 礼物
原题链接
简单
作者:
花终会凋零
,
2022-05-04 15:31:00
,
所有人可见
,
阅读 147
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1010;
typedef long long LL;
struct fee {
int x;
int y;
LL sum;
bool operator < (const fee &t) const
{
return sum < t.sum;
}
} a[N];
int n, b;
int ans;
int main()
{
cin >> n >> b;
for (int i = 1; i <= n; i ++ )
{
cin >> a[i].x >> a[i].y;
a[i].sum = a[i].x / 2 + a[i].y;
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i ++ )
{
int k = 0;
LL total = a[i].x / 2 + a[i].y;
if (total <= b) k ++ ;
for (int j = 1; j <= n; j ++ )
{
if (i == j) continue;
total += (a[j].x + a[j].y);
if (total <= b) k ++ ;
}
ans = max(ans, k);
}
cout << ans << endl;
return 0;
}