F
题意 就是一个人有 n 回合 每回合不能超过 3 代价的花费 问你能造成多少点伤害
第十个回合是双倍攻击
那么我们就意识到了这个很像dp 而且跟卡牌轮次有关系
所以我们定义dp[n][10] 代表第 n 轮 当前是第几张牌次
我们发现代价为 3 总共只有 6 种花费
1 花费打一张 tmp[1]
2 花费打一张 tmp[2]
3 花费打一张 tmp[3]
1 + 1 2花费打 2 张 tmp[4]
1 + 2 3花费打 2 张 tmp[5]
1 + 1 + 1 3花费打三张 tmp[6]
然后注意dp转移过来的时候合法性 也就是初始化问题
然后这题会爆万恶的int!
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
const int MAX_N = 200025;
long long dp[MAX_N][10];
priority_queue<long long> q[15];
long long k[200025],tmp[15],maxx[15];
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n;
scanf("%d",&n);
memset(dp,-1,sizeof(dp));
dp[0][0] = 0;
for(int i = 1;i<=n;++i)
{
int c ,d;
while(!q[1].empty()) q[1].pop();
while(!q[2].empty()) q[2].pop();
while(!q[3].empty()) q[3].pop();
scanf("%d",&k[i]);
for(int j = 1;j<=k[i];++j)
{
scanf("%d%d",&c,&d);
q[c].push(d);
}
for(int j = 0;j<10;++j) dp[i][j] = dp[i-1][j];
for(int j = 1;j<=6;++j) tmp[j] = -inf;
if(!q[1].empty()) tmp[1] = q[1].top();
if(!q[2].empty()) tmp[2] = q[2].top();
if(!q[3].empty()) tmp[3] = q[3].top();
// cout << "ok" <<endl;
if(q[1].size()>=2)
{
long long now = q[1].top();
q[1].pop();
tmp[4] = q[1].top() + now;
maxx[4] = max(q[1].top(),now);
q[1].push(now);
}
// cout << "OK"<<endl;
if(!q[1].empty()&&!q[2].empty())
{
maxx[5] = max(q[1].top(),q[2].top());
tmp[5] = q[1].top()+q[2].top();
}
// cout << "ok" << endl;
if(q[1].size()>=3)
{
maxx[6] = 0;
tmp[6] = q[1].top();
maxx[6] = max(maxx[6],q[1].top());
q[1].pop();
tmp[6] += q[1].top();
maxx[6] = max(maxx[6],q[1].top());
q[1].pop();
tmp[6] += q[1].top();
maxx[6] = max(maxx[6],q[1].top());
q[1].pop();
}
// cout << "ok" <<endl;
if(tmp[1]!=-inf)
{
for(int j = 1;j<=9;++j)
if(dp[i-1][j-1]!=-1) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+tmp[1]);
if(dp[i-1][9]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][9]+tmp[1]*2);
}
if(tmp[2]!=-inf)
{
for(int j = 1;j<=9;++j)
if(dp[i-1][j-1]!=-1) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+tmp[2]);
if(dp[i-1][9]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][9]+tmp[2]*2);
}
if(tmp[3]!=-inf)
{
for(int j = 1;j<=9;++j)
if(dp[i-1][j-1]!=-1) dp[i][j] = max(dp[i][j],dp[i-1][j-1]+tmp[3]);
if(dp[i-1][9]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][9]+tmp[3]*2);
}
if(tmp[4]!=-inf)
{
for(int j = 2;j<=9;++j)
if(dp[i-1][j-2]!=-1) dp[i][j] = max(dp[i][j],dp[i-1][j-2]+tmp[4]);
if(dp[i-1][9]!=-1)dp[i][1] = max(dp[i][1],dp[i-1][9]+tmp[4]+maxx[4]);
if(dp[i-1][8]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][8]+tmp[4]+maxx[4]);
}
if(tmp[5]!=-inf)
{
for(int j = 2;j<=9;++j)
if(dp[i-1][j-2]!=-1)dp[i][j] = max(dp[i][j],dp[i-1][j-2]+tmp[5]);
if(dp[i-1][9]!=-1)dp[i][1] = max(dp[i][1],dp[i-1][9]+tmp[5]+maxx[5]);
if(dp[i-1][8]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][8]+tmp[5]+maxx[5]);
}
if(tmp[6]!=-inf)
{
for(int j = 3;j<=9;++j)
if(dp[i-1][j-3]!=-1)dp[i][j] = max(dp[i][j],dp[i-1][j-3]+tmp[6]);
if(dp[i-1][9]!=-1)dp[i][2] = max(dp[i][2],dp[i-1][9]+tmp[6]+maxx[6]);
if(dp[i-1][8]!=-1)dp[i][1] = max(dp[i][1],dp[i-1][8]+tmp[6]+maxx[6]);
if(dp[i-1][7]!=-1)dp[i][0] = max(dp[i][0],dp[i-1][7]+tmp[6]+maxx[6]);
}
}
long long ans = 0;
for(int i = 0;i<10;++i)
ans = max(ans,dp[n][i]);
printf("%lld\n",ans);
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}