Problem:
Monster Koshien
You are trying to get your monsters to participate in the upcoming Monster Koshien. In the Monster Koshien, there will be several opposing monsters, and you will play against them one-on-one in turn. Whether you win or not, you can move on to the next match. In a match, the three values of speed, strength, and cleverness of the opposing monsters are compared, and the monster with two or more of these values higher wins.
You can adjust the numerical value of your monster to gain an advantage against your opponent's monster. For each gold coin you pay, you can increase the value of one of the three numbers by one size. In exchange, you must decrease the value of one of the other two values by one. The number can be increased as much as you want, but it must be increased or decreased in a non-negative way. The number can be adjusted before each game, and it does not matter how many gold coins you spend. As long as you have gold coins, you can adjust your numbers. The increased or decreased values will be carried over to subsequent matches.
You are getting information about your opponent's monsters and thinking how to play your own monsters.
You are given the numerical value of each of your monsters, the numerical value of each of the monsters they will face before the match, the order in which they will face each other, and the number of gold coins you can spend. Create a program that calculates the maximum number of matches that your monster will win.
Input
The input is given in the following format.
$N$ $C$
$a$ $s$ $w$
$a_1$ $s_1$ $w_1$
：
$a_N$ $s_N$ $w_N$
The first line gives you the number of matches $N$ ($1 \leq N \leq 50$) and the number of gold coins $C$ ($1 \leq C \leq 5000$) that you can spend. The next line will give you the speed ($0 \leq a \leq 100$), strength ($0 \leq s \leq 100$), and cleverness ($0 \leq w \leq 100$) of your monster. The following $N$ lines give the speed ($0 \leq a_i \leq 100$), strength ($0 \leq s_i \leq 100$), and cleverness ($0 \leq w_i \leq 100$) of the $i$th monster to fight.
Output
Output the maximum number of matches your monster will win.
Sample Input and Output
Sample Input 1
2 22
10 30 50
30 100 10
20 50 50
Sample Output 1
2
Sample Input 2
3 30
30 30 0
70 25 20
25 30 60
20 25 90
Sample Output 2
2

Submitted solutions:

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rng(i,l,r) for(int i=(l);i<(r);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrng(i,l,r) for(int i=(r)-1;i>=(l);i--)
#define int long long
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

int dp[59][109][109];
int ndp[59][109][109];

signed main(){
	int N,C;cin>>N>>C;
	rep(t,N+1)rep(i,102)rep(j,102)ndp[t][i][j]=C+1;
	
	auto swp=[&](){
		rep(t,N+1)rep(i,102)rep(j,102){
			dp[t][i][j]=ndp[t][i][j];
			ndp[t][i][j]=C+1;
		}
	};
	swp();
	
	int a,s,w;cin>>a>>s>>w;
	int sm=a+s+w;
	dp[0][a][s]=0;
	int u=N;
	while(u--){
	
		vector<array<int,3>> vs[C+1];
		rep(t,N+1)rep(i,102)rep(j,102)if(dp[t][i][j]<C)vs[dp[t][i][j]].pb({t,i,j});
		
		rep(c,C){
			for(auto&&[t,i,j]:vs[c]){
				if(i+j>sm)continue;
				if(dp[t][i][j]<c)continue;
				
				if(i){
					if(dp[t][i-1][j]>c+1){
						dp[t][i-1][j]=c+1;
						vs[c+1].pb({t,i-1,j});
					}
					
					if(dp[t][i-1][j+1]>c+1){
						dp[t][i-1][j+1]=c+1;
						vs[c+1].pb({t,i-1,j+1});
					}
				}
				
				if(j){
					if(dp[t][i][j-1]>c+1){
						dp[t][i][j-1]=c+1;
						vs[c+1].pb({t,i,j-1});
					}
					if(dp[t][i+1][j-1]>c+1){
						dp[t][i+1][j-1]=c+1;
						vs[c+1].pb({t,i+1,j-1});
					}
				}
				if(sm-i-j){
					if(dp[t][i+1][j]>c+1){
						dp[t][i+1][j]=c+1;
						vs[c+1].pb({t,i+1,j});
					}
					if(dp[t][i][j+1]>c+1){
						dp[t][i][j+1]=c+1;
						vs[c+1].pb({t,i,j+1});
					}
				}
			}
		}
		
		int ai,si,wi;cin>>ai>>si>>wi;
		rep(t,N+1)rep(i,102)rep(j,102){
			if(i+j>sm)continue;
			int cnt=0;
			cnt+=(ai<i);
			cnt+=(si<j);
			cnt+=(wi<sm-i-j);
			chmin(ndp[t+(cnt>=2)][i][j],dp[t][i][j]);
		}
		
		swp();
	}
	
	rrep(t,N+1)rep(i,102)rep(j,102){
		if(dp[t][i][j]<=C){
		//	cout<<t<<" "<<i<<" "<<j<<" "<<dp[t][i][j]<<"\n";
			cout<<t<<"\n";
			return 0;
		}
	}
}
accuracy: 1
time_ms: 450
memory_kb: 37120
final_rank: 4

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;

int dp[2][51][301][301];
const int INF = 1 << 28;

int main(void){
    int n, c;
    cin >> n >> c;
    int ma, ms, mw;
    cin >> ma >> ms >> mw;
    int total = ma + ms + mw;
    vector<int> a(n), s(n), w(n);
    REP(i, 0, n) {
        cin >> a.at(i) >> s.at(i) >> w.at(i);
    }
    REP(i, 0, 2) REP(ii, 0, n + 1) REP(j, 0, 301) REP(k, 0, 301) dp[i][ii][j][k] = INF;
    dp[0][0][ma][ms] = 0;
    REP(i, 0, n) {
        REP(ii, 0, n + 1) REP(j, 0, 301) REP(k, 0, 301) dp[1][ii][j][k] = INF;
        REP(ii, 0, i + 1) {
            REP(x0, 0, total + 1) {
                REP(x1, 0, total - x0 + 1) {
                    if (dp[0][ii][x0][x1] > c) continue;
                    dp[1][ii][x0][x1] = dp[0][ii][x0][x1];
                }
            }
            // (+1, 0) (-1, 0)
            REP(x0, 0, total) {
                REP(x1, 0, total - x0 + 1) {
                    dp[1][ii][x0 + 1][x1] = min(dp[1][ii][x0 + 1][x1], dp[1][ii][x0][x1] + 1);
                }
            }
            for (int x0 = total; x0 >= 1; x0--) {
                REP(x1, 0, total - x0 + 1) {
                    dp[1][ii][x0 - 1][x1] = min(dp[1][ii][x0 - 1][x1], dp[1][ii][x0][x1] + 1);
                }
            }
            // (0, +1) (0, -1)
            REP(x0, 0, total + 1) {
                REP(x1, 0, total - x0) {
                    dp[1][ii][x0][x1 + 1] = min(dp[1][ii][x0][x1 + 1], dp[1][ii][x0][x1] + 1);
                }
            }
            REP(x0, 0, total + 1) {
                for (int x1 = total - x0; x1 >= 1; x1--) {
                    dp[1][ii][x0][x1 - 1] = min(dp[1][ii][x0][x1 - 1], dp[1][ii][x0][x1] + 1);
                }
            }
            // (+1, -1) (-1, +1)
            REP(x0, 0, total + 1) {
                REP(x1, 0, total - x0 + 1) {
                    dp[1][ii][x0 + 1][x1 - 1] = min(dp[1][ii][x0 + 1][x1 - 1], dp[1][ii][x0][x1] + 1);
                }
            }
            for (int x0 = total; x0 >= 1; x0--) {
                REP(x1, 0, total - x0 + 1) {
                    dp[1][ii][x0 - 1][x1 + 1] = min(dp[1][ii][x0 - 1][x1 + 1], dp[1][ii][x0][x1] + 1);
                }
            }
        }
        for (int ii = i; ii >= 0; ii--) {
            REP(x0, 0, total + 1) REP(x1, 0, total - x0 + 1) {
                int x2 = total - x0 - x1;
                int win = (x0 > a.at(i)) + (x1 > s.at(i)) + (x2 > w.at(i)) >= 2;
                if (win) {
                    dp[1][ii + 1][x0][x1] = min(dp[1][ii + 1][x0][x1], dp[1][ii][x0][x1]);
                }
            }
        }
        swap(dp[0], dp[1]);
    }
    int ans = 0;
    REP(ii, 0, n + 1) REP(x0, 0, total + 1) REP(x1, 0, total - x0 + 1) {
        if (dp[0][ii][x0][x1] <= c) {
            ans = max(ans, ii);
        }
    }
    cout << ans << "\n";
    exit(0);
}
accuracy: 1
time_ms: 500
memory_kb: 39740
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int N,C;
    cin>>N>>C;
    int aa,bb,cc;
    cin>>aa>>bb>>cc;
    int n = 105;
    vector<vector<vector<int>>> dp(N+1,vector<vector<int>>(n,vector<int>(n,-1)));
    dp[0][aa][bb] = C;
    for(int ty=0;ty<N;ty++){
        for(int i=0;i<=ty;i++){
            for(int j=0;j<n;j++)for(int k=0;k<n-1;k++) dp[i][j][k+1] = max(dp[i][j][k]-1,dp[i][j][k+1]);
            for(int j=0;j<n;j++)for(int k=n-1;k>0;k--) dp[i][j][k-1] = max(dp[i][j][k]-1,dp[i][j][k-1]);
            for(int j=0;j<n;j++)for(int k=0;k<n-1;k++) dp[i][k+1][j] = max(dp[i][k][j]-1,dp[i][k+1][j]);
            for(int j=0;j<n;j++)for(int k=n-1;k>0;k--) dp[i][k-1][j] = max(dp[i][k][j]-1,dp[i][k-1][j]);
            for(int j=0;j<n-1;j++)for(int k=1;k<n;k++) dp[i][j+1][k-1] = max(dp[i][j+1][k-1],dp[i][j][k]-1);
            for(int j=n-1;j>0;j--)for(int k=0;k<n-1;k++) dp[i][j-1][k+1] = max(dp[i][j-1][k+1],dp[i][j][k]-1);
        }
        int a,b,c;
        cin>>a>>b>>c;
        for(int i=ty;i>=0;i--){
            for(int j=0;j<n;j++)for(int k=0;k<n;k++){
                int l = aa+bb+cc-j-k;
                if(l < 0) continue;
                if((j > a)+(k > b)+(l > c) >= 2){
                    //if(j == 31 && k == 8 && l == 51) cout<<dp[i][j][k]<<endl;
                    dp[i+1][j][k] = max(dp[i+1][j][k],dp[i][j][k]);
                }
            }
        }
    }
    for(int i=N;i>=0;i--){
        for(int j=0;j<n;j++)for(int k=0;k<n;k++)if(dp[i][j][k] >= 0){
            cout<<i<<endl;
            return 0;
        }
    }
}
accuracy: 1
time_ms: 70
memory_kb: 7864
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int N,C;
    cin>>N>>C;
    int aa,bb,cc;
    cin>>aa>>bb>>cc;
    int n = 101;
    vector<vector<vector<int>>> dp(N+1,vector<vector<int>>(n,vector<int>(n,-1)));
    dp[0][aa][bb] = C;
    for(int ty=0;ty<N;ty++){
        for(int i=0;i<=ty;i++){
            for(int j=0;j<n;j++)for(int k=0;k<n-1;k++) dp[i][j][k+1] = max(dp[i][j][k]-1,dp[i][j][k+1]);
            for(int j=0;j<n;j++)for(int k=n-1;k>0;k--) dp[i][j][k-1] = max(dp[i][j][k]-1,dp[i][j][k-1]);
            for(int j=0;j<n;j++)for(int k=0;k<n-1;k++) dp[i][k+1][j] = max(dp[i][k][j]-1,dp[i][k+1][j]);
            for(int j=0;j<n;j++)for(int k=n-1;k>0;k--) dp[i][k-1][j] = max(dp[i][k][j]-1,dp[i][k-1][j]);
            for(int j=0;j<n-1;j++)for(int k=1;k<n;k++) dp[i][j+1][k-1] = max(dp[i][j+1][k-1],dp[i][j][k]-1);
            for(int j=n-1;j>0;j--)for(int k=0;k<n-1;k++) dp[i][j-1][k+1] = max(dp[i][j-1][k+1],dp[i][j][k]-1);
        }
        int a,b,c;
        cin>>a>>b>>c;
        for(int i=ty;i>=0;i--){
            for(int j=0;j<n;j++)for(int k=0;k<n;k++){
                int l = aa+bb+cc-j-k;
                if(l < 0) continue;
                if((j > a)+(k > b)+(l > c) >= 2){
                    //if(j == 31 && k == 8 && l == 51) cout<<dp[i][j][k]<<endl;
                    dp[i+1][j][k] = max(dp[i+1][j][k],dp[i][j][k]);
                }
            }
        }
    }
    for(int i=N;i>=0;i--){
        for(int j=0;j<n;j++)for(int k=0;k<n;k++)if(dp[i][j][k] >= 0){
            cout<<i<<endl;
            return 0;
        }
    }
}
accuracy: 0.8888888888888888
time_ms: 70
memory_kb: 7532
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
	int N,C;
	cin>>N>>C;
	int ma,ms,mw;
	cin>>ma>>ms>>mw;
	int all=ma+ms+mw;
	int a[N+1],s[N+1],w[N+1];
	for(int i=1;i<=N;i++) cin>>a[i]>>s[i]>>w[i];
	int dp[N+1][N+1][all+1][all+1];
	int dp1[N+1][all+1][all+1],dp2[N+1][all+1][all+1];
	for(int i=0;i<=N;i++){
		for(int j=0;j<=all;j++){
			for(int k=0;k<=all;k++){
				dp1[i][j][k]=-1;
				dp2[i][j][k]=-1;
			}
		}
	}
	dp1[0][ma][ms]=C;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			for(int k=0;k<=all;k++){
				for(int l=0;l<=all;l++){
					int pw=all-k-l;
					if(pw<0) continue;
					if(a[i+1]+s[i+1]+2<=all){
						int cost=0;
						cost+=max(0,a[i+1]-k+1)+max(0,s[i+1]-l+1);
						int na,ns;
						na=max(a[i+1]+1,k),ns=max(s[i+1]+1,l);
						if(na+ns>all){
							if(na>a[i+1]+1){
								na=all-ns;
							}
							else{
								ns=all-na;
							}
						}
						dp2[j+1][na][ns]=max(dp2[j+1][na][ns],dp1[j][k][l]-cost);
					}
					if(a[i+1]+w[i+1]+2<=all){
						int cost=0;
						cost+=max(0,a[i+1]-k+1)+max(0,w[i+1]-pw+1);
						int na,ns,nw;
						na=max(a[i+1]+1,k),nw=max(w[i+1]+1,pw);
						if(na+nw>all){
							ns=0;
							if(na>a[i+1]+1) na=all-nw;
							else nw=all-na;
						}
						else ns=all-na-nw;
						
						dp2[j+1][na][ns]=max(dp2[j+1][na][ns],dp1[j][k][l]-cost);
					}
					if(s[i+1]+w[i+1]+2<=all){
						int cost=0;
						cost+=max(0,s[i+1]-l+1)+max(0,w[i+1]-pw+1);
						int na,ns,nw;
						ns=max(s[i+1]+1,l),nw=max(w[i+1]+1,pw);
						if(ns+nw>all){
							na=0;
							if(ns>s[i+1]+1) ns=all-nw;
							else nw=all-ns;
						}
						else na=all-ns-nw;
						dp2[j+1][na][ns]=max(dp2[j+1][na][ns],dp1[j][k][l]-cost);
					}
					dp2[j][k][l]=max(dp2[j][k][l],dp1[j][k][l]);
				}
			}
		}
		for(int j=0;j<=N;j++){
			for(int k=0;k<=all;k++){
				for(int l=0;l<=all;l++){
					dp1[j][k][l]=dp2[j][k][l];
					dp2[j][k][l]=-1;
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<=N;i++){
		for(int j=0;j<=all;j++){
			for(int k=0;k<=all;k++){
				if(dp1[i][j][k]>=0) ans=i;
			}
		}
	}
	cout<<ans<<endl;
}
accuracy: 0.4
time_ms: 10
memory_kb: 4064
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
	int N,C;
	cin>>N>>C;
	int ma,ms,mw;
	cin>>ma>>ms>>mw;
	int all=ma+ms+mw;
	int a[N+1],s[N+1],w[N+1];
	for(int i=1;i<=N;i++) cin>>a[i]>>s[i]>>w[i];
	int dp[N+1][N+1][all+1][all+1];
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			for(int k=0;k<=all;k++){
				for(int l=0;l<=all;l++) dp[i][j][k][l]=-1;
			}
		}
	}
	dp[0][0][ma][ms]=C;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			for(int k=0;k<=all;k++){
				for(int l=0;l<=all;l++){
					int pw=all-k-l;
					if(pw<0) continue;
					if(a[i+1]+s[i+1]+2<=all){
						int cost=0;
						cost+=max(0,a[i+1]-k+1)+max(0,s[i+1]-l+1);
						int na,ns;
						na=max(a[i+1]+1,k),ns=max(s[i+1]+1,l);
						if(na+ns>all){
							if(na>a[i+1]+1){
								na=all-ns;
							}
							else{
								ns=all-na;
							}
						}
						dp[i+1][j+1][na][ns]=max(dp[i+1][j+1][na][ns],dp[i][j][k][l]-cost);
					}
					if(a[i+1]+w[i+1]+2<=all){
						int cost=0;
						cost+=max(0,a[i+1]-k+1)+max(0,w[i+1]-pw+1);
						int na,ns,nw;
						na=max(a[i+1]+1,k),nw=max(w[i+1]+1,pw);
						if(na+nw>all){
							ns=0;
							if(na>a[i+1]+1) na=all-nw;
							else nw=all-na;
						}
						else ns=all-na-nw;
						
						dp[i+1][j+1][na][ns]=max(dp[i+1][j+1][na][ns],dp[i][j][k][l]-cost);
					}
					if(s[i+1]+w[i+1]+2<=all){
						int cost=0;
						cost+=max(0,s[i+1]-l+1)+max(0,w[i+1]-pw+1);
						int na,ns,nw;
						ns=max(s[i+1]+1,l),nw=max(w[i+1]+1,pw);
						if(ns+nw>all){
							na=0;
							if(ns>s[i+1]+1) ns=all-nw;
							else nw=all-ns;
						}
						else na=all-ns-nw;
						dp[i+1][j+1][na][ns]=max(dp[i+1][j+1][na][ns],dp[i][j][k][l]-cost);
					}
					dp[i+1][j][k][l]=max(dp[i+1][j][k][l],dp[i][j][k][l]);
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<=N;i++){
		for(int j=0;j<=all;j++){
			for(int k=0;k<=all;k++){
				if(dp[N][i][j][k]>=0) ans=i;
			}
		}
	}
	cout<<ans<<endl;
}
accuracy: 0.4
time_ms: 10
memory_kb: 21284
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <deque>
#include <stack>
using namespace std;
using ll = long long;
int dp[51][51][120][120];
struct S {
	int id;
	int win;
	int a;
	int s;
};
int main() {
	int N, C;cin >> N >> C;
	int a, s, w;cin >> a >> s >> w;
	int K = 110;
	int T = a + s + w;
	for (int i = 0;i < N+1;i++) for (int j = 0;j < N+1;j++) for (int a = 0;a <= K;a++) for (int b = 0;b <= K;b++) dp[i][j][a][b] = (int)1e9;
	dp[0][0][a][s] = 0;
	deque<pair<int,S>> que;
	que.push_back({0, {0, 0, a, s}});
	vector<int> A(N+1), S(N+1), W(N+1);
	for (int i = 1;i <= N;i++) {
		cin >> A[i] >> S[i] >> W[i];
	}
	while (!que.empty()) {
		auto tps = que.front();que.pop_front();
		int d = tps.first;
		auto tp = tps.second;
		int id = tp.id;int win = tp.win;
		int na = tp.a;int ns = tp.s;
		int nw = T - na - ns;
		if (dp[id][win][na][ns] < d) continue;
		//idの繊維
		if (id+1 <= N) {
			int cnt = 0;
			if (na > A[id+1]) cnt++;
			if (ns > S[id+1]) cnt++;
			if (nw > W[id+1]) cnt++;
			int nwin = win;
			if (cnt >= 2) nwin++;
			if (d < dp[id+1][nwin][na][ns]) {
				dp[id+1][nwin][na][ns]= dp[id][win][na][ns];
				que.push_front({d, {id+1, nwin, na, ns}});
			}
		}
		//ほかの遷移
		for (int i = 0;i < 3;i++) for (int j = 0;j < 3;j++) {
			if (i == j) continue;
			vector<int> now = {na, ns, nw};
			if (now[i] > K) continue;
			if (now[j] <= 0) continue;
			now[i]++;now[j]--;
			int nxa = now[0];int nxs = now[1];
			if (d+1 < dp[id][win][nxa][nxs]) {
				dp[id][win][nxa][nxs] = dp[id][win][na][ns] + 1;
				que.push_back({d+1, {id, win, nxa, nxs}});
			}
		} 
	}
	int res = 0;
	for (int i = 1;i <= N;i++) for (int j = 1;j <= i;j++) for (int a = 0;a <= K;a++) for (int b = 0;b <= K;b++) {
		if (dp[i][j][a][b] <= C) res = max(res, j);
	}
	cout << res << endl;
}
accuracy: 1
time_ms: 1180
memory_kb: 153644
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <deque>
#include <stack>
using namespace std;
using ll = long long;
int dp[51][51][110][110];
struct S {
	int id;
	int win;
	int a;
	int s;
};
int main() {
	int N, C;cin >> N >> C;
	int a, s, w;cin >> a >> s >> w;
	int K = 104;
	int T = a + s + w;
	for (int i = 0;i < N+1;i++) for (int j = 0;j < N+1;j++) for (int a = 0;a <= K;a++) for (int b = 0;b <= K;b++) dp[i][j][a][b] = -1;
	dp[0][0][a][s] = 0;
	deque<S> que;
	que.push_back({0, 0, a, s});
	vector<int> A(N+1), S(N+1), W(N+1);
	for (int i = 1;i <= N;i++) {
		cin >> A[i] >> S[i] >> W[i];
	}	
	while (!que.empty()) {
		auto tp = que.front();que.pop_front();
		int id = tp.id;int win = tp.win;
		int na = tp.a;int ns = tp.s;
		int nw = T - na - ns;
		//idの繊維
		if (id+1 <= N) {
			int cnt = 0;
			if (na > A[id+1]) cnt++;
			if (ns > S[id+1]) cnt++;
			if (nw > W[id+1]) cnt++;
			int nwin = win;
			if (cnt >= 2) nwin++;
			if (dp[id+1][nwin][na][ns]== -1) {
				dp[id+1][nwin][na][ns]= dp[id][win][na][ns];
				que.push_front({id+1, nwin, na, ns});
			}
		}
		//ほかの遷移
		for (int i = 0;i < 3;i++) for (int j = 0;j < 3;j++) {
			if (i == j) continue;
			vector<int> now = {na, ns, nw};
			if (now[i] > K) continue;
			if (now[j] <= 0) continue;
			now[i]++;now[j]--;
			int nxa = now[0];int nxs = now[1];
			if (dp[id][win][nxa][nxs] == -1) {
				dp[id][win][nxa][nxs] = dp[id][win][na][ns] + 1;
				que.push_back({id, win, nxa, nxs});
			}
		} 
	}
	int res = 0;
	for (int i = 1;i <= N;i++) for (int j = 1;j <= i;j++) for (int a = 0;a <= K;a++) for (int b = 0;b <= K;b++) {
		if (dp[i][j][a][b] != -1 and dp[i][j][a][b] <= C) res = max(res, j);
	}
	cout << res << endl;
}
accuracy: 0.4
time_ms: 110
memory_kb: 126904
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 28);

struct Monster {
    int a, b, c;
};

int dp[309][309][109];
int ndp[309][309][109];

int main() {
    // step 1. input
    int n, C; cin >> n >> C;
    int a, b, c; cin >> a >> b >> c;
    int s = a + b + c;
    vector<Monster> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i].a >> p[i].b >> p[i].c;
    }

    // step 2. solve init
    auto reset = [&](int idx) {
        for (int pa = 0; pa <= s; pa++) {
            for (int pb = 0; pb <= s - pa; pb++) {
                for (int win = 0; win <= n; win++) {
                    if (dp[pa][pb][win] == INF) continue;
                    int pc = s - pa - pb;
                    int wins = (pa > p[idx].a ? 1 : 0) + (pb > p[idx].b ? 1 : 0) + (pc > p[idx].c ? 1 : 0);
                    int incr = (wins >= 2 ? 1 : 0);
                    ndp[pa][pb][win + incr] = min(ndp[pa][pb][win + incr], dp[pa][pb][win]);
                }
            }
        }
        for (int pa = 0; pa <= s; pa++) {
            for (int pb = 0; pb <= s - pa; pb++) {
                for (int win = 0; win <= n; win++) {
                    dp[pa][pb][win] = ndp[pa][pb][win];
                    ndp[pa][pb][win] = INF;
                }
            }
        }
    };

    // reset
    for (int pa = 0; pa <= s; pa++) {
        for (int pb = 0; pb <= s; pb++) {
            for (int win = 0; win <= n; win++) {
                dp[pa][pb][win] = INF;
                ndp[pa][pb][win] = INF;
            }
        }
    }
    dp[a][b][0] = 0;
    
    // step 3. solve main
    for (int idx = 0; idx < n; idx++) {
        for (int win = 0; win < n; win++) {
            // a を 1 増やして b を 1 減らす
            for (int pa = 0; pa <= s; pa++) {
                for (int pb = 0; pb <= s - pa; pb++) {
                    int pc = s - pa - pb;
                    if (dp[pa][pb][win] < C && pb >= 1) {
                        dp[pa + 1][pb - 1][win] = min(dp[pa + 1][pb - 1][win], dp[pa][pb][win] + 1);
                    }
                }
            }

            // b を 1 増やして a を 1 減らす
            for (int pa = s; pa >= 0; pa--) {
                for (int pb = 0; pb <= s - pa; pb++) {
                    int pc = s - pa - pb;
                    if (dp[pa][pb][win] < C && pa >= 1) {
                        dp[pa - 1][pb + 1][win] = min(dp[pa - 1][pb + 1][win], dp[pa][pb][win] + 1);
                    }
                }
            }

            // a を 1 増やして c を 1 減らす
            for (int pa = 0; pa <= s; pa++) {
                for (int pb = 0; pb <= s - pa; pb++) {
                    int pc = s - pa - pb;
                    if (dp[pa][pb][win] < C && pc >= 1) {
                        dp[pa + 1][pb][win] = min(dp[pa + 1][pb][win], dp[pa][pb][win] + 1);
                    }
                }
            }

            // c を 1 増やして a を 1 減らす
            for (int pa = s; pa >= 0; pa--) {
                for (int pb = 0; pb <= s - pa; pb++) {
                    int pc = s - pa - pb;
                    if (dp[pa][pb][win] < C && pa >= 1) {
                        dp[pa - 1][pb][win] = min(dp[pa - 1][pb][win], dp[pa][pb][win] + 1);
                    }
                }
            }

            // b を 1 増やして c を 1 減らす
            for (int pa = 0; pa <= s; pa++) {
                for (int pb = 0; pb <= s - pa; pb++) {
                    int pc = s - pa - pb;
                    if (dp[pa][pb][win] < C && pc >= 1) {
                        dp[pa][pb + 1][win] = min(dp[pa][pb + 1][win], dp[pa][pb][win] + 1);
                    }
                }
            }

            // c を 1 増やして b を 1 減らす
            for (int pa = s; pa >= 0; pa--) {
                for (int pb = 0; pb <= s - pa; pb++) {
                    int pc = s - pa - pb;
                    if (dp[pa][pb][win] < C && pb >= 1) {
                        dp[pa][pb - 1][win] = min(dp[pa][pb - 1][win], dp[pa][pb][win] + 1);
                    }
                }
            }
        }

        // すべてをリセット
        reset(idx);
    }

    // output
    int maxn = 0;
    for (int i = 0; i <= s; i++) {
        for (int j = 0; j <= s; j++) {
            for (int k = 0; k <= n; k++) {
                if (dp[i][j][k] <= C) maxn = max(maxn, k);
            }
        }
    }
    cout << maxn << endl;
    return 0;
}
accuracy: 1
time_ms: 1410
memory_kb: 83560
final_rank: 9

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

#define int long long

const int MAXN = 55, MAXS = 105;

signed dp[MAXN][MAXN][MAXS][MAXS];

bool check(int a, int b, int c, int ea, int eb, int ec) {
    int cnt = (a > ea) + (b > eb) + (c > ec);
    return cnt >= 2;
}

const int INF = 2e9;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, c; cin >> n >> c;
    int a, b, c1; cin >> a >> b >> c1;
    vector<int> ea(n), eb(n), ec(n);
    for (int i = 0; i < n; i++) cin >> ea[i] >> eb[i] >> ec[i];
    int sum = a + b + c1;
    for (int i = 0; i < MAXN; i++) {
        for (int j = 0; j < MAXN; j++) {
            for (int k = 0; k < MAXS; k++) {
                for (int s = 0; s < MAXS; s++) {
                    dp[i][j][k][s] = INF;
                }
            }
        }
    }
    dp[0][0][a][b] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (ca + 1 < MAXS) {
                        if (cb > 0) {
                            dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int cb = 0; cb < MAXS; cb++) {
                for (int ca = 0; ca < MAXS; ca++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cb + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int cs = 0; cs < MAXS; cs++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int ca = sum - cs - cb;
                    if (ca < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cs + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                        }
                        if (cb > 0) {
                            dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (check(ca, cb, cs, ea[i], eb[i], ec[i])) {
                        dp[i + 1][j + 1][ca][cb] = min(dp[i + 1][j + 1][ca][cb], dp[i][j][ca][cb]);
                    }
                    else {
                        dp[i + 1][j][ca][cb] = min(dp[i + 1][j][ca][cb], dp[i][j][ca][cb]);
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int a = 0; a < MAXS; a++) {
                for (int b = 0; b < MAXS; b++) {
                    if (dp[i][j][a][b] <= c && dp[i][j][a][b] != 0) {
                        ans = max(ans, j);
                        if (j == 3) {
                            int h = 0;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 160
memory_kb: 133740
final_rank: 6

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

#define int long long

const int MAXN = 55, MAXS = 105;

signed dp[MAXN][MAXN][MAXS][MAXS];

bool check(int a, int b, int c, int ea, int eb, int ec) {
    int cnt = (a > ea) + (b > eb) + (c > ec);
    return cnt >= 2;
}

const int INF = 2e9;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, c; cin >> n >> c;
    int a, b, c1; cin >> a >> b >> c1;
    vector<int> ea(n), eb(n), ec(n);
    for (int i = 0; i < n; i++) cin >> ea[i] >> eb[i] >> ec[i];
    int sum = a + b + c1;
    for (int i = 0; i < MAXN; i++) {
        for (int j = 0; j < MAXN; j++) {
            for (int k = 0; k < MAXS; k++) {
                for (int s = 0; s < MAXS; s++) {
                    dp[i][j][k][s] = INF;
                }
            }
        }
    }
    dp[0][0][a][b] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int h = 0; h < 20; h++) {
                for (int ca = 0; ca < MAXS; ca++) {
                    for (int cb = 0; cb < MAXS; cb++) {
                        int cs = sum - ca - cb;
                        if (cs < 0) break;
                        if (dp[i][j][ca][cb] == INF) continue;
                        if (ca + 1 < MAXS) {
                            if (cb > 0) {
                                dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                            }
                            if (cs > 0) {
                                dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                            }
                        }
                    }
                }
                for (int ca = 0; ca < MAXS; ca++) {
                    for (int cb = 0; cb < MAXS; cb++) {
                        int cs = sum - ca - cb;
                        if (cs < 0) break;
                        if (dp[i][j][ca][cb] == INF) continue;
                        if (cb + 1 < MAXS) {
                            if (ca > 0) {
                                dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                            }
                            if (cs > 0) {
                                dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                            }
                        }
                    }
                }
                for (int ca = 0; ca < MAXS; ca++) {
                    for (int cb = 0; cb < MAXS; cb++) {
                        int cs = sum - ca - cb;
                        if (cs < 0) break;
                        if (dp[i][j][ca][cb] == INF) continue;
                        if (cs + 1 < MAXS) {
                            if (ca > 0) {
                                dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                            }
                            if (cb > 0) {
                                dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                            }
                        }
                    }
                }
                for (int ca = 0; ca < MAXS; ca++) {
                    for (int cb = 0; cb < MAXS; cb++) {
                        int cs = sum - ca - cb;
                        if (cs < 0) break;
                        if (dp[i][j][ca][cb] == INF) continue;
                        if (check(ca, cb, cs, ea[i], eb[i], ec[i])) {
                            dp[i + 1][j + 1][ca][cb] = min(dp[i + 1][j + 1][ca][cb], dp[i][j][ca][cb]);
                        }
                        else {
                            dp[i + 1][j][ca][cb] = min(dp[i + 1][j][ca][cb], dp[i][j][ca][cb]);
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int a = 0; a < MAXS; a++) {
                for (int b = 0; b < MAXS; b++) {
                    if (dp[i][j][a][b] <= c && dp[i][j][a][b] != 0) {
                        ans = max(ans, j);
                        if (j == 3) {
                            int h = 0;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.7333333333333333
time_ms: 1330
memory_kb: 133740
final_rank: 12

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

#define int long long

const int MAXN = 55, MAXS = 105;

signed dp[MAXN][MAXN][MAXS][MAXS];

bool check(int a, int b, int c, int ea, int eb, int ec) {
    int cnt = (a > ea) + (b > eb) + (c > ec);
    return cnt >= 2;
}

const int INF = 2e9;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, c; cin >> n >> c;
    int a, b, c1; cin >> a >> b >> c1;
    vector<int> ea(n), eb(n), ec(n);
    for (int i = 0; i < n; i++) cin >> ea[i] >> eb[i] >> ec[i];
    int sum = a + b + c1;
    for (int i = 0; i < MAXN; i++) {
        for (int j = 0; j < MAXN; j++) {
            for (int k = 0; k < MAXS; k++) {
                for (int s = 0; s < MAXS; s++) {
                    dp[i][j][k][s] = INF;
                }
            }
        }
    }
    dp[0][0][a][b] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int h = 0; h < 10; h++) {
                for (int ca = 0; ca < MAXS; ca++) {
                    for (int cb = 0; cb < MAXS; cb++) {
                        int cs = sum - ca - cb;
                        if (cs < 0) break;
                        if (dp[i][j][ca][cb] == INF) continue;
                        if (ca + 1 < MAXS) {
                            if (cb > 0) {
                                dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                            }
                            if (cs > 0) {
                                dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                            }
                        }
                    }
                }
                for (int ca = 0; ca < MAXS; ca++) {
                    for (int cb = 0; cb < MAXS; cb++) {
                        int cs = sum - ca - cb;
                        if (cs < 0) break;
                        if (dp[i][j][ca][cb] == INF) continue;
                        if (cb + 1 < MAXS) {
                            if (ca > 0) {
                                dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                            }
                            if (cs > 0) {
                                dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                            }
                        }
                    }
                }
                for (int ca = 0; ca < MAXS; ca++) {
                    for (int cb = 0; cb < MAXS; cb++) {
                        int cs = sum - ca - cb;
                        if (cs < 0) break;
                        if (dp[i][j][ca][cb] == INF) continue;
                        if (cs + 1 < MAXS) {
                            if (ca > 0) {
                                dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                            }
                            if (cb > 0) {
                                dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                            }
                        }
                    }
                }
                for (int ca = 0; ca < MAXS; ca++) {
                    for (int cb = 0; cb < MAXS; cb++) {
                        int cs = sum - ca - cb;
                        if (cs < 0) break;
                        if (dp[i][j][ca][cb] == INF) continue;
                        if (check(ca, cb, cs, ea[i], eb[i], ec[i])) {
                            dp[i + 1][j + 1][ca][cb] = min(dp[i + 1][j + 1][ca][cb], dp[i][j][ca][cb]);
                        }
                        else {
                            dp[i + 1][j][ca][cb] = min(dp[i + 1][j][ca][cb], dp[i][j][ca][cb]);
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int a = 0; a < MAXS; a++) {
                for (int b = 0; b < MAXS; b++) {
                    if (dp[i][j][a][b] <= c && dp[i][j][a][b] != 0) {
                        ans = max(ans, j);
                        if (j == 3) {
                            int h = 0;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.7111111111111111
time_ms: 580
memory_kb: 133744
final_rank: 13

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

#define int long long

const int MAXN = 55, MAXS = 105;

signed dp[MAXN][MAXN][MAXS][MAXS];

bool check(int a, int b, int c, int ea, int eb, int ec) {
    int cnt = (a > ea) + (b > eb) + (c > ec);
    return cnt >= 2;
}

const int INF = 2e9;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, c; cin >> n >> c;
    int a, b, c1; cin >> a >> b >> c1;
    vector<int> ea(n), eb(n), ec(n);
    for (int i = 0; i < n; i++) cin >> ea[i] >> eb[i] >> ec[i];
    int sum = a + b + c1;
    for (int i = 0; i < MAXN; i++) {
        for (int j = 0; j < MAXN; j++) {
            for (int k = 0; k < MAXS; k++) {
                for (int s = 0; s < MAXS; s++) {
                    dp[i][j][k][s] = INF;
                }
            }
        }
    }
    dp[0][0][a][b] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (ca + 1 < MAXS) {
                        if (cb > 0) {
                            dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (ca + 1 < MAXS) {
                        if (cb > 0) {
                            dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cb + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cb + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cs + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                        }
                        if (cb > 0) {
                            dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cs + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                        }
                        if (cb > 0) {
                            dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (check(ca, cb, cs, ea[i], eb[i], ec[i])) {
                        dp[i + 1][j + 1][ca][cb] = min(dp[i + 1][j + 1][ca][cb], dp[i][j][ca][cb]);
                    }
                    else {
                        dp[i + 1][j][ca][cb] = min(dp[i + 1][j][ca][cb], dp[i][j][ca][cb]);
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (ca + 1 < MAXS) {
                        if (cb > 0) {
                            dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (ca + 1 < MAXS) {
                        if (cb > 0) {
                            dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cb + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cb + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cs + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                        }
                        if (cb > 0) {
                            dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cs + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                        }
                        if (cb > 0) {
                            dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (check(ca, cb, cs, ea[i], eb[i], ec[i])) {
                        dp[i + 1][j + 1][ca][cb] = min(dp[i + 1][j + 1][ca][cb], dp[i][j][ca][cb]);
                    }
                    else {
                        dp[i + 1][j][ca][cb] = min(dp[i + 1][j][ca][cb], dp[i][j][ca][cb]);
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int a = 0; a < MAXS; a++) {
                for (int b = 0; b < MAXS; b++) {
                    if (dp[i][j][a][b] <= c && dp[i][j][a][b] != 0) {
                        ans = max(ans, j);
                        if (j == 3) {
                            int h = 0;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.3111111111111111
time_ms: 10
memory_kb: 133740
final_rank: 18

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

#define int long long

const int MAXN = 55, MAXS = 105;

signed dp[MAXN][MAXN][MAXS][MAXS];

bool check(int a, int b, int c, int ea, int eb, int ec) {
    int cnt = (a > ea) + (b > eb) + (c > ec);
    return cnt >= 2;
}

const int INF = 2e9;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, c; cin >> n >> c;
    int a, b, c1; cin >> a >> b >> c1;
    vector<int> ea(n), eb(n), ec(n);
    for (int i = 0; i < n; i++) cin >> ea[i] >> eb[i] >> ec[i];
    int sum = a + b + c1;
    for (int i = 0; i < MAXN; i++) {
        for (int j = 0; j < MAXN; j++) {
            for (int k = 0; k < MAXS; k++) {
                for (int s = 0; s < MAXS; s++) {
                    dp[i][j][k][s] = INF;
                }
            }
        }
    }
    dp[0][0][a][b] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (ca + 1 < MAXS) {
                        if (cb > 0) {
                            dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (ca + 1 < MAXS) {
                        if (cb > 0) {
                            dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cb + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cb + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cs + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                        }
                        if (cb > 0) {
                            dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cs + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                        }
                        if (cb > 0) {
                            dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (check(ca, cb, cs, ea[i], eb[i], ec[i])) {
                        dp[i + 1][j + 1][ca][cb] = min(dp[i + 1][j + 1][ca][cb], dp[i][j][ca][cb]);
                    }
                    else {
                        dp[i + 1][j][ca][cb] = min(dp[i + 1][j][ca][cb], dp[i][j][ca][cb]);
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int a = 0; a < MAXS; a++) {
                for (int b = 0; b < MAXS; b++) {
                    if (dp[i][j][a][b] <= c && dp[i][j][a][b] != 0) {
                        ans = max(ans, j);
                        if (j == 3) {
                            int h = 0;
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.17777777777777778
time_ms: 20
memory_kb: 133744
final_rank: 19

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

#define int long long

const int MAXN = 55, MAXS = 105;

signed dp[MAXN][MAXN][MAXS][MAXS];

bool check(int a, int b, int c, int ea, int eb, int ec) {
    int cnt = (a > ea) + (b > eb) + (c > ec);
    return cnt >= 2;
}

const int INF = 3e18;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, c; cin >> n >> c;
    int a, b, c1; cin >> a >> b >> c1;
    vector<int> ea(n), eb(n), ec(n);
    for (int i = 0; i < n; i++) cin >> ea[i] >> eb[i] >> ec[i];
    int sum = a + b + c1;
    for (int i = 0; i < MAXN; i++) {
        for (int j = 0; j < MAXN; j++) {
            for (int k = 0; k < MAXS; k++) {
                for (int s = 0; s < MAXS; s++) {
                    dp[i][j][k][s] = INF;
                }
            }
        }
    }
    dp[0][0][a][b] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (ca + 1 < MAXS) {
                        if (cb > 0) {
                            dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (ca + 1 < MAXS) {
                        if (cb > 0) {
                            dp[i][j][ca + 1][cb - 1] = min(dp[i][j][ca + 1][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca + 1][cb] = min(dp[i][j][ca + 1][cb], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cb + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cb + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb + 1] = min(dp[i][j][ca - 1][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                        if (cs > 0) {
                            dp[i][j][ca][cb + 1] = min(dp[i][j][ca][cb + 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cs + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                        }
                        if (cb > 0) {
                            dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = MAXS - 1; ca >= 0; ca--) {
                for (int cb = MAXS - 1; cb >= 0; cb--) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (cs + 1 < MAXS) {
                        if (ca > 0) {
                            dp[i][j][ca - 1][cb] = min(dp[i][j][ca - 1][cb], dp[i][j][ca][cb] + 1);
                        }
                        if (cb > 0) {
                            dp[i][j][ca][cb - 1] = min(dp[i][j][ca][cb - 1], dp[i][j][ca][cb] + 1);
                        }
                    }
                }
            }
            for (int ca = 0; ca < MAXS; ca++) {
                for (int cb = 0; cb < MAXS; cb++) {
                    int cs = sum - ca - cb;
                    if (cs < 0) break;
                    if (dp[i][j][ca][cb] == INF) continue;
                    if (check(ca, cb, cs, ea[i], eb[i], ec[i])) {
                        dp[i + 1][j + 1][ca][cb] = min(dp[i + 1][j + 1][ca][cb], dp[i][j][ca][cb]);
                    }
                    else {
                        dp[i + 1][j][ca][cb] = min(dp[i + 1][j][ca][cb], dp[i][j][ca][cb]);
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int a = 0; a < MAXS; a++) {
                for (int b = 0; b < MAXS; b++) {
                    if (dp[i][j][a][b] <= c && dp[i][j][a][b] != 0) ans = max(ans, j);
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.022222222222222223
time_ms: 10
memory_kb: 133632
final_rank: 20

code_snippet: //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 999999999999999999LL;
#define double long double
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
struct po{
    double x, y;
};
bool f(po &a, po &b, po &c, po &d) {
	double s, t;
	s = (a.x - b.x) * (c.y - a.y) - (a.y - b.y) * (c.x - a.x);
	t = (a.x - b.x) * (d.y - a.y) - (a.y - b.y) * (d.x - a.x);
	if (s * t > 0)
		return false;
	s = (c.x - d.x) * (a.y - c.y) - (c.y - d.y) * (a.x - c.x);
	t = (c.x - d.x) * (b.y - c.y) - (c.y - d.y) * (b.x - c.x);
	if (s * t > 0)
		return false;
	return true;
}
template <typename T>
bool chmax(T &a, const T& b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T& b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
bool ch(int a, int b, int c){
    if(a < 0)return false;
    if(b < 0)return false;
    if(c < 0)return false;
    if(a > 101)return false;
    if(b > 101)return false;
    if(c > 101)return false;
    return true;
}
int main(){
    ll N, C;
    cin >> N >> C;
    int a, b, c;
    cin >> a >> b >> c;
    int p = a + b + c;
    vvl X(N, vl(3));
    for(int i = 0;i < N;i++){
        for(int j = 0;j < 3;j++){
            cin >> X[i][j];
        }
    }
    deque<vector<int>> D;
    D.push_back({0, 0, a, b});
    vector<vector<vector<vector<int>>>> G(N + 1, vector<vector<vector<int>>>(N + 1, vector<vector<int>>(102, vector<int>(102, C + 1))));
    G[0][0][a][b] = 0;
    vector<pair<int, int>> d = {
        {1, -1}, {1, 0}, {0, 1}, {0, -1}, {-1, 1}, {-1, 0}
    };
    while(!D.empty()){
        vector<int> s = D.front();
        D.pop_front();
        if(s[0] == N)continue;
        int cnt = 0;
        if(s[2] > X[s[0]][0])cnt++;
        if(s[3] > X[s[0]][1])cnt++;
        if(p - s[2] - s[3] > X[s[0]][2])cnt++;
        if(cnt >= 2){
            if(chmin(G[s[0] + 1][s[1] + 1][s[2]][s[3]], G[s[0]][s[1]][s[2]][s[3]])){
                D.push_front({s[0] + 1, s[1] + 1, s[2], s[3]});
            }
        }
        else{
            if(chmin(G[s[0] + 1][s[1]][s[2]][s[3]], G[s[0]][s[1]][s[2]][s[3]])){
                D.push_front({s[0] + 1, s[1], s[2], s[3]});
            }
        }
        for(int i = 0;i < 6;i++){
            int e, f;
            e = s[2] + d[i].first;
            f = s[3] + d[i].second;
            if(ch(e, f, p - e - f)){
                if(chmin(G[s[0]][s[1]][e][f], G[s[0]][s[1]][s[2]][s[3]] + 1)){
                    D.push_back({s[0], s[1], e, f});
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0;i < N + 1;i++){
        for(int j = 0;j < N + 1;j++){
            for(int k = 0;k < 102;k++){
                for(int l = 0;l < 102;l++){
                    if(G[i][j][k][l] <= C){
                        chmax(ans, j);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 750
memory_kb: 127528
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// MLきついよ〜〜〜〜〜〜〜〜〜
// TLもきついよ〜〜〜〜〜〜〜〜〜

std::vector<std::vector<short>> dist[51][51];
const short INF{10000};
short A[50], S[50], W[50];

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    short N, C;
    std::cin >> N >> C;
    short a, s, w;
    std::cin >> a >> s >> w;
    for (int i{} ; i < N ; i++) {
        std::cin >> A[i] >> S[i] >> W[i];
    }
    for (int i{} ; i <= N ; i++) for (int j{} ; j <= i ; j++) 
        dist[i][j] = std::vector(a + s + w + 1, std::vector<short>{});
    for (int p{} ; p <= a + s + w ; p++) {
        int cnt{};
        for (int q{} ; (a + s + w) - (p + q) >= 0 ; q++) {
            cnt++;
        }
        for (int i{} ; i <= N ; i++) {
            for (int j{} ; j <= i ; j++) {
                dist[i][j][p] = std::vector<short>(cnt, INF);
            }
        }
    }
    using T = std::tuple<short, short, short, short>;
    std::deque<T> deq;
    dist[0][0][a][s] = 0;
    deq.emplace_back(0, 0, a, s);
    auto update{[&](short i, short j, short p, short q, short d, bool add) -> void {
        if (i > N) return;
        assert(j <= i);
        assert((a + s + w) - (p + q) >= 0);
        if (dist[i][j][p][q] > d + add) {
            dist[i][j][p][q] = d + add;
            if (add) deq.emplace_back(i, j, p, q);
            else deq.emplace_front(i, j, p, q);
        }
    }};
    while (deq.size()) {
        auto [i, j, p, q]{deq.front()};
        deq.pop_front();
        short r{static_cast<short>((a + s + w) - (p + q))};
        assert(r >= 0);
        short d{dist[i][j][p][q]};
        if (d > C) continue;
        int cnt{(p > A[i]) + (q > S[i]) + (r > W[i])};
        if (cnt >= 2) update(i + 1, j + 1, p, q, d, 0);
        else {
            update(i + 1, j, p, q, d, 0);
            if (p >= 1) {
                update(i, j, p - 1, q + 1, d, 1);
                update(i, j, p - 1, q, d, 1);
            }
            if (q >= 1) {
                update(i, j, p + 1, q - 1, d, 1);
                update(i, j, p, q - 1, d, 1);
            }
            if (r >= 1) {
                update(i, j, p + 1, q, d, 1);
                update(i, j, p, q + 1, d, 1);
            }
        }
    }
    int ans{};
    for (int i{N} ; ans < i and i >= 0 ; i--) {
        for (int j{} ; ans < i and j < (int)dist[N][i].size() ; j++) {
            for (int k{} ; ans < i and k < (int)dist[N][i][j].size() ; k++) {
                if (dist[N][i][j][k] <= C) {
                    ans = i;
                }
            }
        }
    }
    std::cout << ans << '\n';
    std::cout.flush();
    std::quick_exit(0);
}
accuracy: 1
time_ms: 510
memory_kb: 136576
final_rank: 7

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

int main() {
    constexpr int N = 3;
    constexpr int MAX = 102;
    constexpr int INF = 1e9;
    using Table = std::array<int, N>;
    int n;
    int coin;
    std::cin >> n >> coin;
    Table init;
    for (int i = 0; i < N; i++) std::cin >> init[i];
    const int sum = init[0] + init[1] + init[2];
    auto get_c = [&](int a, int b) {
        return sum - a - b;
    };

    // Does lhs win rhs?
    auto win = [&](Table lhs, Table rhs) {
        int count = 0;
        for (int i = 0; i < N; i++) {
            if (lhs[i] > rhs[i]) count++;
        }
        return count >= 2;
    };

    auto always_lose = [&](Table table) {
        std::sort(table.begin(), table.end());
        return table[0] + table[1] + 2 > sum;
    };

    auto valid = [&](Table table) {
        for (int i = 0; i < N; i++) {
            if (table[i] < 0) return false;
        }
        return true;
    };

    // dp[a][b][win] = min coin
    std::vector dp(MAX, std::vector(MAX, std::vector<int>(n + 1, INF)));
    dp[init[0]][init[1]][0] = 0;
    for (int i = 0; i < n; i++) {
        Table enemy;
        for (int j = 0; j < N; j++) std::cin >> enemy[j];
        if (always_lose(enemy)) continue;
        for (int j = i; j >= 0; j--) {
            Table self;
            for (int a = 0; a < MAX; a++) {
                self[0] = a;
                for (int b = 0; b < MAX; b++) {
                    self[1] = b;
                    if (dp[a][b][j] > coin) continue;
                    self[2] = get_c(a, b);
                    if (!valid(self)) continue;
                    if (win(self, enemy)) {
                        dp[a][b][j + 1] = std::min(dp[a][b][j + 1], dp[a][b][j]);
                        continue;
                    }
                    for (int k = 0; k < N; k++) {
                        Table next = self;
                        int diff = 0;
                        for (int l = 0; l < N; l++) {
                            if (k != l && self[l] <= enemy[l]) {
                                next[l] = enemy[l] + 1;
                                diff += enemy[l] + 1 - self[l];
                            }
                        }
                        next[k] -= diff;
                        if (valid(next)) {
                            assert(win(next, enemy));
                            dp[next[0]][next[1]][j + 1] = std::min(dp[next[0]][next[1]][j + 1], dp[a][b][j] + diff);
                        } 
                        int min_i = k;
                        int max_i = -1;
                        for (int l = 0; l < N; l++) {
                            if (k != l && next[l] > enemy[l] + 1) {
                                max_i = l;
                                break;
                            }
                        }
                        if (max_i == -1) continue;
                        while (next[max_i] > enemy[max_i] && self[min_i] >= next[min_i]) {
                            if (valid(next)) {
                                assert(win(next, enemy));
                                dp[next[0]][next[1]][j + 1] = std::min(dp[next[0]][next[1]][j + 1], dp[a][b][j] + diff);
                            }
                            next[max_i]--;
                            next[min_i]++;
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int a = 0; a < MAX; a++) {
        for (int b = 0; b < MAX; b++) {
            for (int i = 0; i <= n; i++) {
                if (dp[a][b][i] <= coin) ans = std::max(ans, i);
            }
        }
    }
    std::cout << ans << std::endl;
}
accuracy: 1
time_ms: 270
memory_kb: 5744
final_rank: 2

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

int main() {
    constexpr int N = 3;
    constexpr int MAX = 102;
    constexpr int INF = 1e9;
    using Table = std::array<int, N>;
    int n;
    int coin;
    std::cin >> n >> coin;
    Table init;
    for (int i = 0; i < N; i++) std::cin >> init[i];
    const int sum = init[0] + init[1] + init[2];
    auto get_c = [&](int a, int b) {
        return sum - a - b;
    };

    // Does lhs win rhs?
    auto win = [&](Table lhs, Table rhs) {
        int count = 0;
        for (int i = 0; i < N; i++) {
            if (lhs[i] > rhs[i]) count++;
        }
        return count >= 2;
    };

    auto always_lose = [&](Table table) {
        std::sort(table.begin(), table.end());
        return table[0] + table[1] + 2 > sum;
    };

    auto valid = [&](Table table) {
        for (int i = 0; i < N; i++) {
            if (table[i] < 0) return false;
        }
        return true;
    };

    // dp[a][b][win] = min coin
    std::vector dp(MAX, std::vector(MAX, std::vector<int>(n + 1, INF)));
    dp[init[0]][init[1]][0] = 0;
    for (int i = 0; i < n; i++) {
        Table enemy;
        for (int j = 0; j < N; j++) std::cin >> enemy[j];
        if (always_lose(enemy)) continue;
        for (int j = i; j >= 0; j--) {
            Table self;
            for (int a = 0; a < MAX; a++) {
                self[0] = a;
                for (int b = 0; b < MAX; b++) {
                    self[1] = b;
                    if (dp[a][b][j] > coin) continue;
                    self[2] = get_c(a, b);
                    if (!valid(self)) continue;
                    if (win(self, enemy)) {
                        dp[a][b][j + 1] = std::min(dp[a][b][j + 1], dp[a][b][j]);
                        continue;
                    }
                    for (int k = 0; k < N; k++) {
                        Table next = self;
                        int diff = 0;
                        for (int l = 0; l < N; l++) {
                            if (k != l && self[l] <= enemy[l]) {
                                next[l] = enemy[l] + 1;
                                diff += enemy[l] + 1 - self[l];
                            }
                        }
                        next[k] -= diff;
                        if (valid(next)) {
                            assert(win(next, enemy));
                            dp[next[0]][next[1]][j + 1] = std::min(dp[next[0]][next[1]][j + 1], dp[a][b][j] + diff);
                        } else {
                            int min_i = k;
                            int max_i = -1;
                            for (int l = 0; l < N; l++) {
                                if (next[l] > enemy[l] + 1) {
                                    max_i = l;
                                    break;
                                }
                            }
                            if (max_i == -1) continue;
                            while (next[max_i] > enemy[max_i] && self[min_i] >= next[min_i]) {
                                if (valid(next)) {
                                    assert(win(next, enemy));
                                    dp[next[0]][next[1]][j + 1] = std::min(dp[next[0]][next[1]][j + 1], dp[a][b][j] + diff);
                                }
                                next[max_i]--;
                                next[min_i]++;
                            }
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int a = 0; a < MAX; a++) {
        for (int b = 0; b < MAX; b++) {
            for (int i = 0; i <= n; i++) {
                if (dp[a][b][i] <= coin) ans = std::max(ans, i);
            }
        }
    }
    std::cout << ans << std::endl;
}
accuracy: 0.4
time_ms: 20
memory_kb: 5720
final_rank: 15

code_snippet: #include<bits/stdc++.h>
#define overload(a,b,c,d,...) d
#define rep1(n) for(ll _=0;_<n;++_)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define rep(...) overload(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,n) for(ll i=(ll)n-1;i>=0;--i)
#define rrep2(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;--i)
#define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define eb emplace_back
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using vl=vector<ll>;
template<typename T,typename U>inline bool chmin(T&a,const U&b){return (a>b?a=b,true:false);}
template<typename T,typename U>inline bool chmax(T&a,const U&b){return (a<b?a=b,true:false);}
static constexpr ll inf=numeric_limits<ll>::max()/2;
/*
struct Segtree2{
	ll lg,n,size;
	vector<ll>data;
	vector<ll>lazy;
	vector<bool>lazy_flag;
	inline static ll op1(ll x,ll y){
		if(y)return -x;
		return x;
	}
	inline static ll op2(ll x,ll y){
		return x^y;
	}
	inline void update(ll k){
		data[k]=data[k<<1]+data[k<<1|1];
	}	
	void all_apply(ll k,ll x,ll sz){
		data[k]=op1(data[k],x);
		if(k<size){
			if(lazy_flag[k])lazy[k]=op2(lazy[k],x);
			else lazy[k]=x,lazy_flag[k]=true;
		}
	}
	void eval(ll k,ll sz){
		if(lazy_flag[k]){
			all_apply(k<<1,lazy[k],sz>>1);
			all_apply(k<<1^1,lazy[k],sz>>1);
			lazy_flag[k]=false;
		}
	}
	public:
	Segtree2(const vector<ll>&x){
		n=x.size();
		lg=0;while((1<<lg)<n)lg++;
		size=1<<lg;
		data.resize(size<<1,0);
		lazy.resize(size);
		lazy_flag.assign(size,false);
		rep(i,n)data[i+size]=x[i];
		rrep(i,1,size)update(i);
	}
	void apply(ll l,ll r,ll x){
		if(l==r)return;
		l+=size,r+=size;
		ll lst=lg+1;
		rrep(i,1,lg+1){
			if(((l>>i)<<i)!=l)eval(l>>i,1<<i),lst=i;
			if(((r>>i)<<i)!=r)eval((r-1)>>i,1<<i),lst=i;
			if(lst!=i)break;
		}
		for(ll l2=l,r2=r,sz=1;l2!=r2;l2>>=1,r2>>=1,sz<<=1){
			if(l2&1)all_apply(l2++,x,sz);
			if(r2&1)all_apply(--r2,x,sz);
		}
		rep(i,lst,lg+1){
			if(((l>>i)<<i)!=l)update(l>>i);
			if(((r>>i)<<i)!=r)update((r-1)>>i);
		}
	}
	ll prod(ll l,ll r){
		if(l==r)return 0;
		l+=size,r+=size;
		rrep(i,1,lg+1){
			bool f=false;
			if(((l>>i)<<i)!=l)eval(l>>i,1<<i),f=true;
			if(((r>>i)<<i)!=r)eval((r-1)>>i,1<<i),f=true;
			if(!f)break;
		}
		ll sum=0;
		while(l!=r){
			if(l&1)sum+=data[l++];
			if(r&1)sum+=data[--r];
			l>>=1,r>>=1;
		}
		return sum;
	}
	ll operator[](ll k){
		k+=size;
		rrep(i,1,lg+1)eval(k>>i,1<<i);
		return data[k-size];
	}
};*/
/*
struct RollingHash{
	using ull=unsigned long long;
	using i128=__uint128_t;
	private:
	static constexpr ull MOD=(1ull<<61)-1;
	static constexpr ull MASK31=(1ull<<31)-1;
	static ull calc_mod(ull a){
		ull ret=(a&MOD)+(a>>61);
		if(ret>=MOD)ret-=MOD;
		return ret;
	}
	static ull calc_mul(ull a,ull b){
		i128 c=(i128)a*b;
		return calc_add(c&MOD,c>>61);
	}
	static ull calc_add(ull a,ull b){
		ull ret=a+b;
		if(ret>=MOD)ret-=MOD;
		return ret;
	}
	ull BASE;
	void init(){
		BASE=(1ull<<31)+(random_device()()&MASK31);
	}
	public:
	struct Hash{
		private:
		int n;
		ull BASE;
		vector<ull>inner_hash,power;
		public:
		template<typename T>
		Hash(ull base,const T&s):BASE(base){
			n=s.size();
			inner_hash.resize(n+1);
			for(int i=0;i<n;++i)inner_hash[i+1]=calc_add(s[i],calc_mul(BASE,inner_hash[i]));
			power.resize(n+1);power[0]=1;
			for(int i=0;i<n;i++)power[i+1]=calc_mul(power[i],BASE);
		}
		ull get_hash(int l,int r)const{
			return calc_add(inner_hash[r],MOD-calc_mul(inner_hash[l],power[r-l]));
		}
		ull get_all()const{
			return inner_hash[n];
		}
		size_t size()const{return n;}
	};
	RollingHash(){init();}
	template<typename T>
	Hash get_hash(const T&s)const{return  Hash(BASE,s);}
};*/
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n,c,a,s,w;
	cin>>n>>c>>a>>s>>w;
	const ll sum=a+s+w;
	vector<vector<vl>>dp(n+1,vector<vl>(sum+1,vl(sum+1,inf)));
	dp[0][a][s]=0;
	rep(i,n){
		ll na,ns,nw;cin>>na>>ns>>nw;
		rrep(j,i+1){
			rep(k,sum+1){
				rep(l,sum-k+1){
				 	if(sum-(k+l))chmin(dp[j][k+1][l],dp[j][k][l]+1),chmin(dp[j][k][l+1],dp[j][k][l]+1);
					if(l)chmin(dp[j][k+1][l-1],dp[j][k][l]+1);
				}
			}
			rrep(k,sum+1)rrep(l,sum-k+1){
				if(k)chmin(dp[j][k-1][l+1],dp[j][k][l]+1),chmin(dp[j][k-1][l],dp[j][k][l]+1);
				if(l)chmin(dp[j][k][l-1],dp[j][k][l]+1);
				ll m=sum-(k+l);
				ll cnt=(k>na)+(l>ns)+(m>nw);
				if(cnt>=2)chmin(dp[j+1][k][l],dp[j][k][l]);
			}
		}
	}
	rrep(i,n+1)rep(j,sum+1)rep(k,sum+1){
		if(dp[i][j][k]<=c){
			cout<<i<<endl;return 0;
		}
	}
}
accuracy: 1
time_ms: 250
memory_kb: 40236
final_rank: 3