Codeforces Round #740 (Div. 2) C. Deep Down Below

对于每个洞穴,假设我们刚进入时的攻击力是x,则x>a1,x+1>a2,x+2>a3…我们将常数项移到右边得x>a1,x>a2-1,x>a3-2,x>ai-(i-1),我们要想所有得不等式成立,即取所有ai-(i-1)得最大值。
同理对于每个洞穴间再推一次这样得不等式变换求得最大值再加1就是我们得答案。
AC代码:

#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int,int> PII;
const int N=1e6+5;
int n;
void solve() {
	cin>>n;
	vector<PII>q;
	for(int i=0;i<n;i++){
		vector<int>a;
		int m,k=0;
		cin>>m;
		for(int j=0;j<m;j++){
			int x;
			cin>>x;
			a.push_back(x);
			k=max(k,x-j);//将不等式化为统一形式,求最大值 
		}
		q.push_back({k,m});
	}
	
	sort(q.begin(),q.end());
	int maxx=0,sum=0;
	for(int i=0;i<q.size();i++){
		maxx=max(maxx,q[i].x-sum);
		sum+=q[i].y;
	} 
	cout<<maxx+1<<endl;
}

main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	//init();
	int T;
	cin>>T;
	while(T--)solve();
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值