fork download
  1. #include<bits/stdc++.h>
  2.  
  3. #define INF 1000010000
  4. #define nl '\n'
  5. #define pb push_back
  6. #define ppb pop_back
  7. #define mp make_pair
  8. #define fi first
  9. #define se second
  10. #define pii pair<int,int>
  11. #define pdd pair<double,double>
  12. #define all(c) (c).begin(), (c).end()
  13. #define SORT(c) sort(all(c))
  14. #define sz(c) (c).size()
  15. #define rep(i,n) for( int i = 0; i < n; ++i )
  16. #define repi(i,n) for( int i = 1 ; i <= n; ++i )
  17. #define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
  18. #define repf(j,i,n) for( int j = i ; j < n ; ++j )
  19. #define die(s) {std::cout << s << nl;}
  20. #define dier(s) {std::cout << s; return 0;}
  21. #define dbg(var) {std::cout << #var << " = " << var << nl;}
  22. #define vi vector<int>
  23. typedef long long ll;
  24.  
  25. using namespace std;
  26.  
  27. constexpr int MAXN = 2e5 + 15;
  28.  
  29. ll dp[MAXN][11] = { -1LL };
  30.  
  31. int main() {
  32. ios_base::sync_with_stdio(false);
  33. cin.tie(NULL);
  34. cout.precision(0);
  35.  
  36. int n;
  37. cin >> n;
  38.  
  39. vector<vector<pii>> turns(n);
  40. rep(i , n)
  41. {
  42. int k;
  43. cin >> k;
  44. rep(j , k)
  45. {
  46. int c , d;
  47. cin >> c >> d;
  48. turns[i].emplace_back(c , d);
  49. }
  50. }
  51.  
  52. rep(i , n)
  53. {
  54. map<int , vi> cur;
  55. for(auto& el : turns[i]) cur[el.fi].pb(el.se);
  56. for(auto& el : cur) sort(all(el.se) , std::greater<int>());
  57.  
  58. rep(j , 10) dp[i][j] = -1LL;
  59.  
  60. dp[i][0] = 0LL;
  61.  
  62. static const vector<vi> ways =
  63. { // 1 2 3
  64. { 1 , 0 , 0 },
  65. { 0 , 1 , 0 },
  66. { 0 , 0 , 1 },
  67. { 2 , 0 , 0 },
  68. { 1 , 1 , 0 },
  69. { 3 , 0 , 0 },
  70. { 0 , 0 , 0 }
  71. };
  72.  
  73. for(auto& way : ways)
  74. {
  75. vector<ll> d;
  76. bool good = true;
  77. rep(j , 3)
  78. {
  79. if(cur[1 + j].size() < way[j])
  80. {
  81. good = false;
  82. break;
  83. }
  84. rep(l , way[j])
  85. {
  86. d.pb(cur[1 + j][l]);
  87. }
  88. }
  89. if(!good) continue;
  90.  
  91. sort(all(d) , std::greater<ll>());
  92.  
  93. const int cards = accumulate(all(way) , 0);
  94. rep(j , 10)
  95. {
  96. dp[i][cards] = max(dp[i][cards] , accumulate(all(d) , 0LL));
  97.  
  98. if(i > 0 && dp[i - 1][j] != -1)
  99. {
  100. auto dd = d;
  101. if(j + cards >= 10) dd[0] *= 2;
  102.  
  103. dp[i][(j + cards) % 10] = max(dp[i][(j + cards) % 10] , dp[i - 1][j] + accumulate(all(dd) , 0LL));
  104. }
  105. }
  106. }
  107. }
  108.  
  109.  
  110.  
  111.  
  112. ll ans = 0;
  113. rep(i , n)
  114. {
  115. rep(j , 10)
  116. {
  117. ans = max(ans , dp[i][j]);
  118. }
  119. }
  120.  
  121. cout << ans << nl;
  122.  
  123. return 0;
  124. }
Success #stdin #stdout 0s 32432KB
stdin
4
3
1 1
1 1
1 1
3
1 1
1 1
1 1
3
1 1
1 1
1 1
3
1 1
1 1
1 1
stdout
13