Problem:
C : 壺 / Pots
問題文
ここに
N
個の不思議な形の壺がある．
i
番目の壺は
K_i
個の直円柱を下から順に鉛直に繋げた形状である． 繋がっている順番は変えることができない． A 氏は体積
M
の水を持っている． この水をそれぞれの壺に好きな量ずつに分けて注ぐ． 水が全く入っていない壺が存在しても構わない． また，全ての壺が水で満たされたとき，それ以上水を注ぐ事はできない．それぞれの壺の水面の高さの総和の最大値を求めよ．
入力
N \ M
K_1 \ S_{11} \ H_{11} \ … \ S_{1 K_1} \ H_{1 K_1}
K_2 \ S_{21} \ H_{21} \ … \ S_{2 K_2} \ H_{2 K_2}
…
K_N \ S_{N1} \ H_{N1} \ … \ S_{N K_N} \ H_{N K_N}
1
行目に
N, M
が，
1+i
行目には
i
番目の壺の情報が入力される．
K_i
は直円柱の数であり，
S_{ij}, H_{ij}
はそれぞれ壺を構成する下から
j
番目の直円柱の底面積と高さである．
制約
整数である
1 ≤ N ≤ 200
1 ≤ M ≤ 200
1 ≤ K_i ≤ 20
1 ≤ S_{ij} ≤ 20
1 ≤ H_{ij} ≤ 20
出力
答えを
1
行で出力せよ．
0.00001
以下の絶対誤差を含んでも良い．
サンプル
サンプル入力1
2 15
2 3 3 7 2
2 7 1 1 4
サンプル出力1
6.33333333
サンプル入力2
2 14
1 2 4
2 5 2 1 4
サンプル出力2
6
サンプル 1, 2 の入出力を図示すると次のようになる．
サンプル入力3
2 25
4 8 9 1 9 6 5 2 8
4 1 7 4 4 1 6 4 3
サンプル出力3
13

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define FOR(i,s,t )for(int i = s; i <t ; i++)
using LL = long long; using ll = LL;
using PLL = pair<LL, LL>; using  pll = PLL;
using PII = pair<int, int>; using  pii = PII;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
using VI = vector<int>;
using VVI = vector<VI>;
#define debug(x) cout<<#x<<":="<<x
double f(int k, int m, VI &S, VI &T) {
	// kth Sに,m L いれるときの高さ
	int left = m;
	double ret = 0;
	FOR(i, 0, SZ(S)) {
		double Cap = S[i] * T[i];
		if (left > Cap) {
			ret += T[i];
			left -= Cap;
		}
		else {
			ret += left*1.0 / S[i];
			left = 0;
			break;
		}
	}
	return ret;
}


void solve() {
	int N, M; cin >> N >> M;

	VI K(N);
	VVI S(N), T(N);
	FOR(i, 0, N) {
		cin >> K[i];
		S[i] = vector<int>(K[i]);
		T[i] = vector<int>(K[i]);
		FOR(j, 0, K[i]) {
			cin >> S[i][j] >> T[i][j];
		}
	}
	double dp[202][202];
	fill(*dp, *dp + 102 * 102, 0);

	FOR(i, 0, N) {
		FOR(base, 0, M+1) {
			FOR(add, 0, M+1) {
				if (base + add <= M)
					dp[i + 1][base + add] = max(dp[i + 1][base + add], dp[i][base] + f(i, add, S[i], T[i]));
				//cout << i << ",add=" << add<<", "; debug(f(i, add, S[i], T[i])) << endl;
			}
		}
	}
	cout <<fixed<<setprecision(10)<< dp[N][M] << endl;

}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	solve();

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3876
final_rank: 8

code_snippet: #include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  double dp[223][223];
  fill(dp[0],dp[223],-1e9);
  dp[0][0]=0;
  for(int i=0;i<N;i++){
    int K;
    cin>>K;
    int S[22],H[22];
    for(int j=0;j<K;j++){
      cin>>S[j]>>H[j];
    }
    for(int j=0;j<=M;j++){
      int x=0;
      int t=0;
      int h=0;
      for(int k=0;k+j<=M;k++){
	if(x==K){
	  dp[i+1][j+k]=max(dp[i+1][j+k],dp[i][j]+h);
	  break;
	}
	dp[i+1][j+k]=max(dp[i+1][j+k],dp[i][j]+h+t*1./S[x]);
	t++;
	if(t==H[x]*S[x]){
	  t=0;
	  h+=H[x];
	  x++;
	}
      }
    }
  }
  cout<<fixed<<*max_element(dp[0],dp[223])<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3692
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;
#define ll long long

const double eps = 1e-6;

int main(){
    int n; cin >> n;
    int m; cin >> m;
    vector<int> k(n);
    vector s(n, vector<double>());
    vector h(n, vector<double>());
    for(int i = 0; i < n; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            int s_, h_; cin >> s_ >> h_;
            s[i].push_back(s_);
            h[i].push_back(h_);
        }
    }
    vector best(n, vector<double>(m+1, -1e10));
    auto calc = [&](int u, double v) -> double {
        double res = 0;
        int i = 0;
        while(v > eps && i < k[u]){
            if(v > s[u][i]*h[u][i]){
                res += h[u][i];
                v -= h[u][i]*s[u][i];
            } else {
                double height = v / s[u][i];
                res += height;
                v = 0;
            }
            i++;
        }
        // cout << v << " " << res << '\n';
        if(v > eps) return -1e10;
        else return res;
    };

    for(int v = 0; v < m+1; v++){
        best[0][v] = calc(0, v);
    }
    for(int i = 1; i < n; i++){
        for(int v1 = 0; v1 < m+1; v1++){
            for(int v2 = 0; v2 <= v1; v2++){
                best[i][v1] = max(best[i][v1] ,calc(i, v2) + best[i-1][v1-v2]);
                // cout << v1 << " " << v2 << " " << best[i-1][v1-v2] << " " << calc(i, v2) << '\n';
            }
        }
    }

    // cout << calc(0, 4) << "\n";

    // for(int i  = 0; i < m+1; i++){
    //     cout << best[0][i] << '\n';
    // }

    cout << fixed << setprecision(10) << best[n-1][m] << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3800
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vpll=vector<pll>;
using vvll=vector<vll>;
using vvld=vector<vector<ld>>;
using vvpll=vector<vpll>;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=(1LL<<61)-1;
void vout(vector<ld> a){
  rep(i,(ll)a.size()-1)cout<<a[i]<<" ";
  cout<<a[a.size()-1]<<endl;
}
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}

int main(){
  ll n,m;
  cin>>n>>m;
  vvpll v(n);
  rep(i,n){
    ll k;
    cin>>k;
    rep(j,k){
      ll s,h;
      cin>>s>>h;
      v[i].push_back({s,h});
    }
  }

  vvld h(n);
  rep(i,n)h[i].resize(m+1);
  rep(i,n){
    ll hight=0;
    ll water=0;
    rep(j,(ll)v[i].size()){
      water+=v[i][j].first*v[i][j].second;
      if(water>m)break;
      hight+=v[i][j].second;
      h[i][water]=hight;
    }
    ll x=0;
    for(ll j=1;j<=m;j++){
      if(h[i][j]==0){
        if(x>=(ll)v[i].size())h[i][j]=h[i][j-1];
        else h[i][j]=h[i][j-1]+(ld)1/v[i][x].first;
      }
      else x++;
    }
  }
  // rep(i,n)vout(h[i]);

  vvld dp=h;
  rep(i,n-1){
    rep(j,m+1){
      rep(k,m+1){
        if(j>=k)chmax(dp[i+1][j],dp[i][j-k]+h[i+1][k]);
      }
    }
  }
  cout<<fixed<<setprecision(10);
  cout<<dp[n-1][m]<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4448
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define rrep(i, s, t) for(ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define TT template<typename T>
TT using vec = vector<T>;
TT using minheap = priority_queue<T, vector<T>, greater<T>>;
TT using maxheap = priority_queue<T>;

struct io_setup {
    io_setup() {
        ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        cout << fixed << setprecision(15);
    }
} io_setup;


TT bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }
TT bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }

TT int LB(vector<T>& v, T x) { return lower_bound(all(v), x) - begin(v);}
TT int UB(vector<T>& v, T x) { return upper_bound(all(v), x) - begin(v);}

const int inf = 1001001001;
const ll INF = 2002002002002002002;


struct dsu {
    using vi = vector<int>;   
    using vvi = vector<vector<int>>;
    private:
    vi par;
    vi sz;
    int cc;
    vi es;

    public:

    dsu(int n) {
        par.resize(n);
        sz.resize(n, 1);
        es.resize(n, 0);
        cc = n;
        rep(i, 0, n) {
            par[i] = i;
        }
    }
  
    int leader(int u) {
        if (par[u] != u) {
            return par[u] = leader(par[u]);
        }    
         return u;
    }
    
    bool same(int a, int b) {
        return leader(a) == leader(b);
    }
    
    bool merge(int a, int b) {
        a = leader(a), b = leader(b);
        if(sz[a] < sz[b]) swap(a, b);

        if(a == b) {
            ++es[a];
            return false;
        }
        else {
            cc--;
            par[b] = leader(a);
            sz[a] += sz[b];
            es[a] += es[b] + 1;
            return true;
        }
    }

    int size(int u) {
        return sz[leader(u)];
    }

    
    int componentcnt() {
        return cc;
    }


    
    int edgecnt(int u) {
        return es[leader(u)];
    }

    vvi groups() {
        int n = par.size();
        vvi ms(n);
        rep(v, 0, n) {
            ms[leader(v)].push_back(v);
        }

        vvi res;
        rep(i, 0, n) if(ms[i].size() > 0) {
            res.push_back(ms[i]);
        }

        return res;
    }

};

/*
@brief dsu
@docs doc/dsu.md
*/

int main() {
	ll N, M;
	cin >> N >> M;

	vec<ll> K(N);
	vec<vec<ll>> S(N);
	vec<vec<ll>> H(N);

	rep(i, 0, N) {
		cin >> K[i];
		S[i].resize(K[i]);
		H[i].resize(K[i]);
		rep(j, 0, K[i]) cin >> S[i][j] >> H[i][j];
	}

	vec<double> dp(M+1, -inf);
	dp[M] = 0;

	auto cal = [&](ll id, ll T) {
		double res = 0;

		rep(i, 0, K[id]) if(T > 0) {
			ll use = min(T, S[id][i] * H[id][i]);
			if(use == S[id][i] * H[id][i]) {
				T -= use;
				res += H[id][i];
			}
			else {
				res += double(T)/S[id][i];
				break;
			}
		}
		return res;
	};

	rep(ti, 0, N) {
		vec<double> pre(M+1, -inf);
		swap(dp, pre);
		rep(l, 0, M+1) {
			rep(use, 0, l+1) {
				ll nl = l - use;
				chmax(dp[nl], pre[l] + cal(ti,use));
			}
		}
	}

	cout << dp[0] << endl;
	
}
accuracy: 1
time_ms: 10
memory_kb: 3640
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define all(a) (a).begin(), (a).end()
using ld = long double;

int main(){
    ll n,m;
    cin >> n >> m;

    vector<vector<ld>> dp(n+1,vector<ld>(m+1, 0));

    rep(i,1,n+1){
        int K;
        cin >> K;
        vector<ld> s(K),h(K);
        rep(j,0,K) cin >> s[j] >> h[j];
        vector<ld> p(m+1,0);
        p[0] = 0;
        int nw = 0;
        rep(j,0,K){
            rep(k, 0, s[j] * h[j] + 1){
                if(nw + k < m+1) p[nw + k] = p[nw] + (ld)k / s[j];
            }
            nw += s[j] * h[j];
        }
        
        rep(j, 1, m+1) {
            p[j] = max(p[j], p[j-1]);
        }
        rep(j,0,m+1){
            rep(k,0,j+1){
                dp[i][j] = max(dp[i][j], dp[i-1][j-k] + p[k]);
            }
        }
    }

    cout << fixed << setprecision(10);
    cout << dp[n][m] << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4100
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
using ll = long long;
using ld = long double;
const ll INF = (1ll<<61) - 1;
template<class T> bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
#define all(p) p.begin(),p.end()


int main(){
    int N,M;
    cin>>N>>M;
    vector<ld> dp(M+1);
    rep(rop,0,N){
        int K;
        cin>>K;
        vector<int> S(K),H(K);
        rep(i,0,K) cin>>S[i]>>H[i];
        vector<ld> p(M+1);
        int ind=0;
        int Y=0;
        int X=0;
        rep(i,1,M+1){
            if(ind==K){
                p[i]=Y;
            }
            else{
                if(X+S[ind]*H[ind]==i){
                    X=i;
                    Y+=H[ind++];
                    p[i]=Y;
                }
                else{
                    p[i]=Y+((ld)(i-X))/(ld)(S[ind]);
                }
            }
            //cout<<i<<" "<<p[i]<<endl;
        }
        vector<ld> n_dp(M+1);
        rep(i,0,M+1) rep(j,i,M+1){
            chmax(n_dp[j],dp[i]+p[j-i]);
        }
        swap(n_dp,dp);
    }
    cout<<fixed<<setprecision(20)<<dp[M]<<"\n";
}
accuracy: 1
time_ms: 10
memory_kb: 3584
final_rank: 1

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const double EPS = 1e-11, PI = acos(-1);
//ここから編集
ll modPow(ll x, ll n, ll mod = MOD){
    ll res = 1;
    while(n){
        if(n&1) res = (res * x)%mod;
 
        res %= mod;
        x = x * x %mod;
        n >>= 1;
    }
    return res;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n, m;
  cin >> n >> m;
  
  vector<int> K(n);
  vector<vector<int>> S(n), H(n);
  REP(i,n){
    cin >> K[i];
    S[i].resize(K[i]);
    H[i].resize(K[i]);
    for(int j=0; j<K[i]; j++){
      cin >> S[i][j] >> H[i][j];
    }
  }
  double ans = 0.0;
  for(int i=0; i<n; i++){
    /* 最終的な高さがdoubleになるものを固定する */

    vector<vector<int>> dp(n+1, vector<int>(m+1,-1));
    dp[0][0] = 0;
    for(int j=0; j<n; j++){
      if(i == j) {
        for(int k=0; k<=m; k++){
          dp[j+1][k] = max(dp[j+1][k], dp[j][k]);
        }
      }else{
        for(int k=0; k<=m; k++){
          int sum = 0;
          int va = 0;
          for(int l=0; l<K[j]; l++){
            int s = S[j][l], h = H[j][l];
            va += s*h;
            sum += h;
            if(k-va >= 0 && dp[j][k-va] != -1){
              dp[j+1][k] = max(dp[j+1][k], dp[j][k-va] + sum);
            }
            dp[j+1][k] = max(dp[j+1][k], dp[j][k]);
          }
        }
      }
      
    }


    for(int j=0; j<=m; j++){
      if(dp[n][j] == -1) continue;    
      int sum = 0;
    int va = 0;
      double nokori = m-j;
      for(int k=0; k<K[i]; k++){
        int s = S[i][k], h = H[i][k];
        va += s*h;
        sum += h;
        
        if(nokori >= va){
          ans = max(ans, (double)(dp[n][j] + sum));

        }else{
          double newnokori = nokori - (va-s*h);
          //cout << newnokori << endl;
          ans = max(ans, (double)dp[n][j] + newnokori/(double)s + (double)(sum-h));
          break;
        }
      }
    }
    
  }cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 3448
final_rank: 13

code_snippet: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

double s[210][22];
double h[210][22];

signed main(){
    
    double n, m; cin >> n >> m;
    vector<int> k(n);
    
    for(int i = 0; i < n; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j] >> h[i][j];
        }
    }
    
    double ans = 0.0;

    for(int ii = 0; ii < n; ii++){

        vector<vector<double> > dp(n + 1, vector<double> (m + 1, -1.0));
        dp[0][0] = 0.0;
        for(int i = 0; i < n; i++){
        
            if(ii == i){
                for(int j = 0; j <= m; j++) dp[i + 1][j] = dp[i][j];
                continue;
            }


            for(int j = 0; j <= m; j++){
                if(dp[i][j] < 0.0) continue;

                int nj = j;
                dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j]);
                double val = 0.0;
                for(int l = 0; l < k[i]; l++){
                    // とるぜ
                    nj += s[i][l] * h[i][l];
                    val += h[i][l];
                    if(nj <= m) dp[i + 1][nj] = max(dp[i + 1][nj], dp[i][j] + val); 
                }
            }
        }
        
        for(int j = 0; j <= m; j++){
            
            double rest = m - j;
            double high = 0.0;

            for(int l = 0; l < k[ii]; l++){
                if(rest >= s[ii][l] * h[ii][l]){
                    rest -= s[ii][l] * h[ii][l];
                    high += h[ii][l];
                }else{
                    high += rest / s[ii][l];
                    break;
                }
            }
            
            if(dp[n][j] != -1.0) ans = max(ans, dp[n][j] + high);
        }

    }

    printf("%.10f\n", ans);

    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3488
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<double> > hei(n);
	for(int i=0; i<n; i++){
		int k;
		cin >> k;
		hei[i].push_back(0);
		for(int j=0; j<k; j++){
			int s,h;
			cin >> s >> h;
			for(int d=0; d<s*h; d++){
				hei[i].push_back(hei[i].back()+(double)1/s);
			}
		}
	}

	vector<double> dp(m+1, 0);
	for(int i=0; i<n; i++){
		auto ndp = dp;
		for(int j=1; j<(int)hei[i].size(); j++){
			for(int k=m; k>=0; k--){
				if(k+j > m) continue;
				ndp[k+j] = max(ndp[k+j], dp[k]+hei[i][j]); 
			}
		}
		dp = ndp;
	}
	cout << fixed << setprecision(10);
	cout << *max_element(dp.begin(), dp.end()) << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5304
final_rank: 12

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2754>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

double clac(int n,int add,vector<int>& S,vector<int>& H){
    double ret = 0;
    int sz = (int)S.size();
    for(int i = 0; i < sz;i++){
        int V = S[i]*H[i];
        if(add >= V){
            ret += H[i];
            add -= V;
        }else{
            ret += H[i]*add/(double)V;
            break;
        }
    }
    return ret;
}
double solve(){
    double res = 0;
    int N,M; cin >> N >> M;
    vector<int> K(N);
    vector<vector<int>> S(N),H(N);
    for(int i = 0; i < N;i++){
        cin >> K[i];
        S[i].resize(K[i]); H[i].resize(K[i]);
        for(int j = 0; j < K[i];j++){
            cin >> S[i][j] >> H[i][j];
        }
    }
    
    vector<vector<double>> dp(N+1,vector<double>(M+1,0));
    for(int i = 0; i < N;i++){
        for(int j = 0; j <= M;j++){
            for(int k = 0; k <= M; k++){
                if(j + k > M)continue;
                dp[i+1][j+k] = max(dp[i+1][j+k],dp[i][j] + clac(i,k,S[i],H[i]));
            }
        }
    }
    res = dp[N][M];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12) <<  solve() << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3420
final_rank: 6

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Data{
	int S,H,V_ruiseki,H_ruiseki;
};

struct Info{
	int K;
	Data data[20];
};

double dp[201][201];

int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	Info info[N];
	int V_sum,H_sum,all_V_sum = 0,all_H_sum = 0;

	for(int i = 0; i < N; i++){
		scanf("%d",&info[i].K);
		V_sum = 0;
		H_sum = 0;

		for(int a = 0; a < info[i].K; a++){
			scanf("%d %d",&info[i].data[a].S,&info[i].data[a].H);
			all_V_sum += info[i].data[a].S*info[i].data[a].H;
			all_H_sum += info[i].data[a].H;
			V_sum += info[i].data[a].S*info[i].data[a].H;
			H_sum += info[i].data[a].H;
			info[i].data[a].V_ruiseki = V_sum;
			info[i].data[a].H_ruiseki = H_sum;
		}
	}

	if(all_V_sum <= M){
		printf("%d\n",all_H_sum);
		return 0;
	}

	for(int i = 0; i <= N; i++){
		for(int k = 0; k <= M; k++)dp[i][k] = -1.0;
	}

	dp[0][M] = 0.0;

	double height;
	int next_rest,num;

	for(int pot = 0; pot < N; pot++){
		for(int rest = 0; rest <= M; rest++){
			if(dp[pot][rest] == -1.0)continue;
			for(int water = 0; water <= rest; water++){

				for(num = 0; num < info[pot].K; num++){
					if(info[pot].data[num].V_ruiseki > water){
						break;
					}
				}

				if(num == info[pot].K){
					height = (double)info[pot].data[info[pot].K-1].H_ruiseki;
					next_rest = water-info[pot].data[info[pot].K-1].V_ruiseki;
					dp[pot+1][next_rest] = max(dp[pot+1][next_rest],dp[pot][rest]+height);
				}else{

					if(num == 0){
						height = (double)water/(double)info[pot].data[num].S;
					}else{
						height = (double)info[pot].data[num-1].H_ruiseki+(double)(water-info[pot].data[num-1].V_ruiseki)/(double)info[pot].data[num].S;
					}
					dp[pot+1][rest-water] = max(dp[pot+1][rest-water],dp[pot][rest]+height);
				}
			}
		}
	}

	printf("%.10lf\n",dp[N][0]);

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3596
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
int k[202];
int s[202][22],h[202][22];
double c[202][202];
int ma[202];
double memo[202][202];
double dfs(int p,int x){
  if(memo[p][x]>=0) return memo[p][x];
  if(p==n) return 0; 
  double res=0;
  for(int i=0;i<=min(x,ma[p]);i++){
    res=max(res,dfs(p+1,x-i)+c[p][i]);
  }
  //cout<<p<<" "<<x<<" "<<res<<endl;
  return memo[p][x]=res;
}
signed main(){
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>s[i][j]>>h[i][j];
    }
  }
  for(int i=0;i<n;i++){
    ma[i]=0;
    for(int j=0;j<k[i];j++) ma[i]+=s[i][j]*h[i][j];
    for(int j=0;j<=ma[i];j++){
      queue<int> q;
      for(int r=0;r<k[i];r++)
	for(int l=0;l<h[i][r];l++) 
	  q.push(s[i][r]);
      double tmp=0;
      int x=0;
      while(!q.empty()){
	int p=q.front();q.pop();
	if(x+p>j){
	  tmp+=(double)(j-x)/p;
	  break;
	}
	x+=p;
	tmp+=1;
      }
      //cout<<i<<" "<<j<<" "<<ma[i]<<" "<<tmp<<endl;
      c[i][j]=tmp;
    }
  }
  for(int i=0;i<202;i++)
    for(int j=0;j<202;j++)
      memo[i][j]=-1;
  printf("%.12f\n",dfs(0,m));
  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 3952
final_rank: 14

code_snippet: #include<bits/stdc++.h>
#define N 205
#define W 21
using namespace std;

int n,m;
int dp[N][N][W];

int main(){
  
  cin>>n>>m;
  
  int k,s,h;
  vector<int> v[N];
  
  for(int i=0;i<n;i++){
    cin>>k;
    
    for(int j=0;j<k;j++){
      cin>>s>>h;
      for(int l=0;l<h;l++)
	v[i].push_back(s);
    }
  }
  
  memset(dp,-1,sizeof(dp));
  dp[0][0][0]=0;
  
  for(int i=0;i<n;i++){
    
    for(int j=0;j<=m;j++){
      
      for(int l=0;l<W;l++){
	if(dp[i][j][l]==-1)continue;
	
	int sum=0;
	for(int x=0;x<v[i].size();x++){
	  
	  sum+=v[i][x];
	  int w=l;
	  
	  if(x<v[i].size()-1){
	    if(!l)w=v[i][x+1];
	    else w=min(l,v[i][x+1]);
	  }
	  
	  if(j+sum<=m)dp[i+1][j+sum][w]=max(dp[i+1][j+sum][w],dp[i][j][l]+x+1);
	  
	}
	dp[i+1][j][l]=max(dp[i+1][j][l],dp[i][j][l]);
	
      }
      
    }
    
  }

  double ans=0;
  for(int i=0;i<=m;i++){
    for(int j=0;j<W;j++){
      
      if(dp[n][i][j]==-1)continue;
      
      if(j&&1.0*m-i<=j)ans=max(ans,dp[n][i][j]+(1.0*m-i)/j);
      else ans=max(ans,1.0*dp[n][i][j]);
    }
  }

  printf("%.8f\n",ans);
  
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 6868
final_rank: 17

code_snippet: #include<bits/stdc++.h>
#define N 205
#define W 21
using namespace std;

int n,m;
int dp[N][N][W];

int main(){
  
  cin>>n>>m;
  
  int k,s,h;
  vector<int> v[N];
  
  for(int i=0;i<n;i++){
    cin>>k;
    
    for(int j=0;j<k;j++){
      cin>>s>>h;
      for(int l=0;l<h;l++)
	v[i].push_back(s);
    }
  }
  
  memset(dp,-1,sizeof(dp));
  dp[0][0][0]=0;
  
  for(int i=0;i<n;i++){
    
    for(int j=0;j<=m;j++){
      
      for(int l=0;l<W;l++){
	if(dp[i][j][l]==-1)continue;
	
	int sum=0;
	for(int x=0;x<v[i].size();x++){
	  
	  sum+=v[i][x];
	  int w=l;
	  
	  if(x<v[i].size()-1){
	    if(!l)w=v[i][x+1];
	    else w=min(l,v[i][x+1]);
	  }
	  
	  if(j+sum<=m)dp[i+1][j+sum][w]=max(dp[i+1][j+sum][w],dp[i][j][l]+x+1);
	  
	}
	dp[i+1][j][l]=max(dp[i+1][j][l],dp[i][j][l]);
	
      }
      
    }
    
  }

  double ans=0;
  for(int i=0;i<=m;i++){
    for(int j=0;j<W;j++){
      
      if(dp[n][i][j]==-1)continue;
      
      if(j&&1.0*m-i<=j*j)ans=max(ans,dp[n][i][j]+(1.0*m-i)/j);
      else ans=max(ans,1.0*dp[n][i][j]);
    }
  }

  printf("%.8f\n",ans);
  
  return 0;
}
accuracy: 0.19298245614035087
time_ms: 50
memory_kb: 6764
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
struct Pot{
  int S;
  int H;
  Pot():S(0),H(0){}
  Pot(int S, int H):S(S),H(H){}
};

double height(const int idx, const int water_, const vector< vector< Pot > >& P){
  double res = 0.0;
  double water = (double)water_;
  vector<Pot> p = P[idx];

  for(int i = 0; i < p.size(); i++){
    Pot pot = p[i];
    int pot_size = p[i].S * p[i].H;
    if(water >= pot_size){
      res += p[i].H;
      water -= pot_size;
    }else{
      res += water / p[i].S;
      break;
    }
  }
  return res;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  vector< vector< Pot > > P(N);
  for(int i = 0; i < N; i++){
    int K; cin >> K;
    for(int j = 0; j < K; j++){
      int S, H; cin >> S >> H;
      P[i].push_back( Pot(S, H) );
    }
  }

  double dp[N+1][M+1];
  for(int i = 0; i <= N; i++) for(int j = 0; j <= M; j++) dp[i][j] = -5000;

  for(int j = 0; j <= M; j++){
    dp[0][M-j] = height(0, j, P);
    //cout << dp[0][j] << endl;
  }

  for(int i = 1; i < N; i++){
    for(int j = M; j >= 0; j--){
      for(int k = 0; k <= j; k++){
        dp[i][j-k] = max(dp[i][j-k], dp[i-1][j] + height(i, k, P));
      }
    }
  }

  //cout << dp[1][1] << endl;
  double ans = 0;
  for(int j = 0; j <= M; j++){
    ans = max(ans, dp[N-1][j]);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3588
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
int k[22];
int s[202][22],h[202][22];
double c[202][202];
int ma[202];
double memo[202][202];
double dfs(int p,int x){
  if(memo[p][x]>=0) return memo[p][x];
  if(p==n) return 0; 
  double res=0;
  for(int i=0;i<=min(x,ma[p]);i++){
    res=max(res,dfs(p+1,x-i)+c[p][i]);
  }
  //cout<<p<<" "<<x<<" "<<res<<endl;
  return memo[p][x]=res;
}
signed main(){
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>s[i][j]>>h[i][j];
    }
  }
  for(int i=0;i<n;i++){
    ma[i]=0;
    for(int j=0;j<k[i];j++) ma[i]+=s[i][j]*h[i][j];
    for(int j=0;j<=ma[i];j++){
      queue<int> q;
      for(int r=0;r<k[i];r++)
	for(int l=0;l<h[i][r];l++) 
	  q.push(s[i][r]);
      double tmp=0;
      int x=0;
      while(!q.empty()){
	int p=q.front();q.pop();
	if(x+p>j){
	  tmp+=(double)(j-x)/p;
	  break;
	}
	x+=p;
	tmp+=1;
      }
      //cout<<i<<" "<<j<<" "<<ma[i]<<" "<<tmp<<endl;
      c[i][j]=tmp;
    }
  }
  for(int i=0;i<202;i++)
    for(int j=0;j<202;j++)
      memo[i][j]=-1;
  printf("%.12f\n",dfs(0,m));
  return 0;
}
accuracy: 0.08771929824561403
time_ms: 10
memory_kb: 3528
final_rank: 20

code_snippet: #include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

class Pot {
public:
	vector<double> S, H;
	double f(double k) {
		double ret = 0;
		dumpc(S);
		dumpc(H);
		rep(i, 0, S.size()) {
			if (k == 0)break;
			double h = min(k / S[i], H[i]);
			dump(h);
			k -= h*S[i];
			dump(k);
			ret += h;
			dump(ret);
		}
		return ret;
	}
};

#define MAX_N 210
#define MAX_M 210
double dp[MAX_N][MAX_M] = {};
vector<Pot> Pots;
double dfs(int i, int j) {
	if (i == 0)return 0;
	if (dp[i][j] != -1)return dp[i][j];
	rep(k, 0, j + 1) {
		dump(i - 1);
		dump(k);
		dump(Pots[i - 1].f(k));
		dp[i][j] = max(dfs(i - 1, j - k) + Pots[i - 1].f(k), dp[i][j]);
	}
	dump(i);
	dump(j);
	dump(dp[i][j]);
	return dp[i][j];
}

signed main() {
	cout << fixed << setprecision(8);
	fill(dp[0], dp[MAX_N], -1);
	int N, M; cin >> N >> M;
	Pots.resize(N);
	rep(i, 0, N) {
		int K; cin >> K;
		rep(j, 0, K) {
			double S, H; cin >> S >> H;
			Pots[i].S.emplace_back(S);
			Pots[i].H.emplace_back(H);
		}
	}
	cout << dfs(N, M) << endl;
	if(DBG)rep(i, 0, N + 1) {
		cout << dp[i][0];
		rep(j, 1, M+1) { cout << " " << dp[i][j]; }
		cout << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3680
final_rank: 9

code_snippet: #include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

class Pot {
public:
	vector<double> S, H;
	double f(double k) {
		double ret = 0;
		dumpc(S);
		dumpc(H);
		rep(i, 0, S.size()) {
			if (k == 0)break;
			double h = min(k / S[i], H[i]);
			dump(h);
			k -= h*S[i];
			dump(k);
			ret += h;
			dump(ret);
		}
		return ret;
	}
};

#define MAX_N 210
#define MAX_M 210
double dp[MAX_N][MAX_M] = {};
vector<Pot> Pots;
double dfs(int i, int j) {
	if (i == 0)return 0;
	if (dp[i][j] != -1)return dp[i][j];
	rep(k, 0, j + 1) {
		dump(i - 1);
		dump(k);
		dump(Pots[i - 1].f(k));
		dp[i][j] = max(dfs(i - 1, j - k) + Pots[i - 1].f(k), dp[i][j]);
	}
	dump(i);
	dump(j);
	dump(dp[i][j]);
	return dp[i][j];
}

signed main() {
	fill(dp[0], dp[MAX_N], -1);
	int N, M; cin >> N >> M;
	Pots.resize(N);
	rep(i, 0, N) {
		int K; cin >> K;
		rep(j, 0, K) {
			double S, H; cin >> S >> H;
			Pots[i].S.emplace_back(S);
			Pots[i].H.emplace_back(H);
		}
	}
	cout << dfs(N, M) << endl;
	if(DBG)rep(i, 0, N + 1) {
		cout << dp[i][0];
		rep(j, 1, M+1) { cout << " " << dp[i][j]; }
		cout << endl;
	}
	return 0;
}
accuracy: 0.19298245614035087
time_ms: 10
memory_kb: 3604
final_rank: 18

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

ld getheight(const vector<pair<int, int>>&pot, ld water) {
	ld h = 0;
	for (int i = 0; i < pot.size(); ++i) {
		if (water > pot[i].first*pot[i].second) {
			h += pot[i].second;
			water -= pot[i].first*pot[i].second;
		}
		else {
			return h + water / pot[i].first;
		}
	}
	return h;
}

int main() {
	int N;ld M; cin >> N >> M;
	vector<vector<pair<int, int>>>pots;
	for (int i = 0; i < N; ++i) {
		int K; cin >> K;
		vector<pair<int, int>>pot;
		for (int j = 0; j < K; ++j) {
			int s, h; cin >> s >> h;
			pot.push_back(make_pair(s, h));

		}
		pots.emplace_back(pot);
	}
	vector<vector<ld>>dp(N + 1, vector<ld>(M + 1));
	for (int i = 0; i < N; ++i) {
		const vector<pair<int, int>>apot(pots[i]);
		for (int j = 0; j <= M; ++j) {

			for (int use = 0; use <= M - j; ++use) {
				dp[i + 1][j + use] = max(dp[i][j] + getheight(apot, use), dp[i + 1][j + use]);
			}
		}
	}
	cout << setprecision(10) << fixed << dp[N][M] << endl;
	
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3404
final_rank: 5