Educational Codeforces Round 85 (Rated for Div. 2)C. Circle of Monsters

Educational Codeforces Round 85 (Rated for Div. 2)C. Circle of Monsters

题目大意:

n个点,每个点两个属性 a i a_i ai 代表生命值, b i b_i bi 代表死亡后会对 a i + 1 a_{i+1} ai+1 造成 b i b_i bi 的伤害, b n b_n bn a 1 a_1 a1。另外你的每次攻击伤害为 1,问最小攻击次数。

思路:

  • 想办法先把 b i b_i bi 属性解决掉。我们将每个 b i b_i bi 先提前用掉,得到 c i c_i ci 这是我们必须要施加的攻击从而触发 b i b_i bi,但是最开始还需要有个点先到达 c i c_i ci

input:

1
3
7 15
2 14
5 3

output:

6

code:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define Please return 
#define Accepted 0
#define int long long
#define endl "\n"
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double, double> PDD;
const int N = 300010,M=2*N,INF=0x3f3f3f3f;
int n;
int a[N],b[N],c[N];
void slove(int _case)
{
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i]>>b[i];
	int sum=0;
	for(int i=1;i<n;i++)
	{
		c[i+1]=max(0ll,a[i+1]-b[i]);
		sum+=c[i+1];
	}
	c[1]=max(0ll,a[1]-b[n]);
	sum+=c[1];
	int ans=1e18;
	for(int i=1;i<=n;i++)
	{
		ans=min(ans,sum-c[i]+a[i]);
	}
	cout<<ans<<endl;
}

signed main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T=1;
	cin>>T;
	for(int _case=1;_case<=T;_case++)
	{
		slove(_case);
	}
	Please Accepted;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值