P14635 [NOIP2025] 糖果店 / candy
zhangzirui66 · · 题解
首先注意到
我们选择
注意到购买完批量购买的糖果之后还会有一些钱,用来买单独的糖果,这一颗糖果显然也要买最便宜的那款,不用考虑购买两颗这款糖果,因为批量购买都买不起了,它自然也买不起。
因此存储
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m, a[1000005], sum[1000005], ans;
signed main(){
cin >> n >> m;
for(int i = 1; i <= n; i ++){
int x, y; cin >> x >> y;
a[i] = x; sum[i] = x + y;
}
sort(a + 1, a + n + 1);
sort(sum + 1, sum + n + 1);
ans = m / sum[1] * 2; // 全部批量买
for(int i = 1; i <= n; i ++){
if(a[i] <= m){
m -= a[i];
ans = max(ans, m / sum[1] * 2 + i);
}
}
cout << ans;
return 0;
}