Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))--C. Deep Down Below

Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))–C. Deep Down Below

In a certain video game, the player controls a hero characterized by a single integer value: power. The hero will have to beat monsters that are also characterized by a single integer value: armor.

On the current level, the hero is facing nn caves. To pass the level, the hero must enter all the caves in some order, each cave exactly once, and exit every cave safe and sound. When the hero enters cave ii, he will have to fight kiki monsters in a row: first a monster with armor ai,1ai,1, then a monster with armor ai,2ai,2 and so on, finally, a monster with armor ai,kiai,ki.

The hero can beat a monster if and only if the hero’s power is strictly greater than the monster’s armor. If the hero can’t beat the monster he’s fighting, the game ends and the player loses. Note that once the hero enters a cave, he can’t exit it before he fights all the monsters in it, strictly in the given order.

Each time the hero beats a monster, the hero’s power increases by 11.

Find the smallest possible power the hero must start the level with to be able to enter all the caves in some order and beat all the monsters.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1051≤t≤105). Description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1051≤n≤105) — the number of caves.

The ii-th of the next nn lines contains an integer kiki (1≤ki≤1051≤ki≤105) — the number of monsters in the ii-th cave, followed by kiki integers ai,1,ai,2,…,ai,kiai,1,ai,2,…,ai,ki (1≤ai,j≤1091≤ai,j≤109) — armor levels of the monsters in cave ii in order the hero has to fight them.

It is guaranteed that the sum of kiki over all test cases does not exceed 105105.

Output

For each test case print a single integer — the smallest possible power the hero must start the level with to be able to enter all the caves in some order and beat all the monsters.

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int a[100005];
int main() {
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        memset(a,0,sizeof a);
        vector<pair<int,int>>v;
        for(int i=1;i<=n;i++){
            int x;cin>>x;
            for(int k=0,z;k<x;k++){
                cin>>z;
                a[i]=max(a[i],z+1-k);
            }
            v.push_back(make_pair(a[i],x));
        }
        sort(v.begin(),v.end());
        int ans=0,sum=0;
        for(int i=0;i<v.size();i++){
            ans=max(ans,v[i].first-sum);
            sum+=v[i].second;
        }
        cout<<ans<<endl;
    }
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

独一无二的VV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值