对于每个洞穴,假设我们刚进入时的攻击力是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();
}