跳到正文

题解

P14635 [NOIP2025] 糖果店 / candy(民间数据)题解

pies_0x约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年11月29日
收录
2026年7月10日
更新
2026年10月25日
篇幅
约 2 分钟
获赞
2
题目
P14635

版本

  1. v1当前

P14635 [NOIP2025] 糖果店 / candy(民间数据)题解

首先, 每种糖果的选取分为两部分:

  1. A 部分:单独的一个 xix_i
  2. B 部分:多组 xi+yix_i+y_i

只会有一种糖果会有 B 部分,即 xi+yix_i+y_i 最小的那种。因为如果有其他糖果包含 B 部分,可以用这种糖果进行替代。

A 部分是独立的,贪心地尽量取 xix_i 小的即可。最后,我们枚举 kk,取 xix_i 前 kk 小的 xix_i,剩下的则全是 B 部分。

C++
#include<cstdio>
#include<algorithm>
using namespace std;

#define N 100005
#define int long long

namespace code
{
	int n,m;
	struct candy
	{
		int x,y;
	} candies[N];
	
	signed main()
	{
		scanf("%lld%lld",&n,&m);
		int t=9e18;
		for(int i=1;i<=n;++i)
			scanf("%lld%lld",&candies[i].x,&candies[i].y),
			t=min(t,candies[i].x+candies[i].y);
		sort(candies+1,candies+n+1,[](candy a,candy b){return a.x<b.x;});
		int ans=m/t<<1;
		for(int i=1;i<=n;++i)
			if((m-=candies[i].x)>=0)
				ans=max(ans,i+(m/t<<1));
		printf("%lld",ans);
		return 0;
	}
}

signed main()
{
	code::main();
	return 0;
}
原文