题解 | #Sum#

Sum

https://ac.nowcoder.com/acm/contest/38457/A

B 差分;遍历一遍找最小值即可

using namespace std;
typedef long long LL;
const int N = 1e6+21;
LL nums[N], ans, res;
int main()
{
	int n,m; cin>>n>>m;
	while(n--) {
		int a,b,c;
		cin>>a>>b>>c;
		// 差分  / ans 为 胜利n层的总得分
		nums[a] += c, nums[b+1] -= c, ans += c;
	}
	res = 1e18;
	for(int i = 1; i <= m; ++i) {
		nums[i] = nums[i-1] +nums[i];
		res = min(nums[i],res); // 找最小得分的debuf的得分
	}// 全部分数 - 最小debuf得分
	cout<<ans-res;
}
全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务