璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:luogup6625
problems
名称卡牌游戏
题目编号P6625
题目链接luogu.com.cn/…
来源Luogu
算法分类前缀和, 贪心
难易程度容易

卡牌游戏

想法

每次操作就是将某一个前缀和加入到总和里,所以从第二个前缀和开始,只要是产生收益的前缀和均加入到总和里。

代码实现

#include<cstdio>
const int N = 1e5+10;
long long int line[N], sum[N], ans;
int main() {
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; i++) {
		scanf("%lld", &line[i]);
		sum[i] = sum[i-1] + line[i];
		if(sum[i] > 0 && i != 1)
			ans += sum[i];
	}
	printf("%lld", ans);
	return 0;
}
/app/www/public/data/pages/icpc/problems/luogup6625.txt · 最后更改: 2024/02/17 11:20 由 温婕莺