【堆】膳食搭配


逆向思维。将时间线倒过来,变成xxx时间点出现某种食物。
然后每次吃最少的那种食物即可。


代码

#include<bits/stdc++.h>
using namespace std;
int n, c, rs, ans, bhh, X[200005];
long long tt, lt, lll;
struct asdf{
	int t;
	long long k;
	int bh;
} F[200005];
struct foood{
	long long num;
	int bh;
	bool operator < (const foood& cmp) const{ //定义小于号
		return num < cmp.num;
	} 
};
bool cmp(asdf aa, asdf bb){
	return aa.t > bb.t;
}
int main(){
	priority_queue<foood> q; 
	scanf("%d%d", &n, &c);
	for(int i = 1; i <= n; ++i){
		scanf("%d%lld", &F[i].t, &F[i].k);
		F[i].bh = i;
	}
	sort(F+1, F+1+n, cmp);
	rs = 0;
	while(rs < n){
		++rs; tt = F[rs].t;
		while(F[rs].t == tt && rs <= n){
			q.push((foood){-F[rs].k, F[rs].bh});
			++rs;
		}
		lt = tt - F[rs].t; //食用时间 
		--rs;
		lt = lt * c; //食用量 
		while(!q.empty() && lt){
			if(-q.top().num <= lt) {
				lt += q.top().num;
				X[++ans] = q.top().bh;
				q.pop();
			}
			else{
				lll = -q.top().num - lt;
				bhh = q.top().bh;
				q.pop();
				q.push((foood){-lll, bhh});
				break;
			}
		}
	}
	printf("%d\n", ans);
	sort(X+1, X+1+ans);
	for(int i = 1; i <= ans; ++i)
		printf("%d ", X[i]);
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值