专栏文章

P14167 [Algo Beat Contest 002.5 B] 草莓小蛋糕 (cakes)

P14167题解参与者 1已保存评论 0

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
0 条
当前快照
1 份
快照标识符
@minnqdmb
此快照首次捕获于
2025/12/02 05:24
3 个月前
此快照最后确认于
2025/12/02 05:24
3 个月前
查看原文
故事能不能再具体一点,尺度稍微……
贪心思想是优先吃容易变质的蛋糕,就像你会先吃保质期更短的食物一样。
用结构体排一下,然后秒杀。
按种类枚举,模拟一下,每次减去变质损失的值,加上美味值之和就行啦。
CPP
#include <bits/stdc++.h>
using namespace std;
const __int128 N=100010;
int n;
__int128 ans;
struct ST{
	__int128 c,d,x;
}a[N];
int cmp(ST q,ST p){//排序函数 
	return q.x>p.x;
}
__int128 read() {//用题目给的输入输出 
    char c;
    bool isf = 0;
    while (!isdigit(c = getchar())) {
    	isf = (c == '-');
    }
    __int128 res = (c ^ 48);
    while (isdigit(c = getchar())) {
    	res = (res << 3) + (res << 1) + (c ^ 48);
    }
    return isf ? -res : res;
}
void write(__int128 x) {
    if (x < 0) {
    	putchar('-'), x = -x;
    } 
    if (x >= 10) {
    	write(x / 10);
    }
    putchar('0' + x % 10);
}
int main(){
	ios::sync_with_stdio(0); 
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		a[i].c=read();
		a[i].d=read();
		a[i].x=read();
	}
	sort(a+1,a+1+n,cmp);
	__int128 day=0;//到第几天了 
	for(int i=1;i<=n;i++){//运算 
		ans-=day*a[i].x*a[i].c;
		ans-=a[i].c*(a[i].c-1)/2*a[i].x;
		ans+=a[i].d*a[i].c;
		day+=a[i].c;
	}
	write(ans);
	return 0;
}

评论

0 条评论,欢迎与作者交流。

正在加载评论...