Problem:
D： 優柔不断 - Indecision -
問題
えびちゃんは最近ギャルゲーにハマっていて、今の目標は二人のヒロインを同時に攻略することです。
えびちゃんはいくつかあるイベントを利用してヒロインからの好感度を高めることができますが、各イベントの対象として選べるヒロインはどちらか一人のみです。しかし、えびちゃんは選ばなかったヒロインに対してもフォローを忘れないので、もう片方のヒロインからの好感度もある程度は高めることができます。ただし、イベントには費用がかかるため、必ずしも全てのイベントを行えるわけではありません。
さて、優柔不断なえびちゃんは各イベントをどちらのヒロインと行うか（またはどちらとも行わないか）で迷っています。えびちゃんは片方のヒロインからの好感度だけが高くても他方が低ければ意味がないと思っているので、好感度が高くない方のヒロインからの好感度が最大となる選択が理想です。
このとき、好感度が高くない方のヒロインからの好感度の最大値を求めてください。すなわち、イベントおよび対象ヒロインの選択の結果、ふたりのヒロインからの好感度をそれぞれ
A
、
B
としたときの、min
\{A, B\}
として考えうる値の最大値を求めてください。ここで、行うことにしたイベントに掛かる費用の合計が予算を超えてはいけません。また、各ヒロインからの好感度の初期値は
0
です。
入力形式
N
C
a_1
b_1
c_1
…
a_N
b_N
c_N
1
行目にはイベントの候補の数
N
と予算
C
が空白区切りで与えられる。
1+i
行目
(1 \leq i \leq N)
には
i
番目のイベントについて、それを行うヒロインの好感度の増分
a_i
と他方のヒロインの好感度の増分
b_i
、およびそれらにかかる費用
c_i
が空白区切りで与えられる。
制約
1 \leq N \leq 100
1 \leq C \leq 100
1 \leq b_i < a_i \leq 100
1 \leq c_i \leq 100
出力形式
問題文中の理想的な選択の下で、好感度が高くない方のヒロインからの好感度の最大値を一行に出力せよ。
入力例1
3 4
3 2 2
2 1 1
2 1 1
出力例1
5
最初の二つのイベントを片方のヒロインと、最後のイベントをもう片方のヒロインと行うのが最善です。
入力例2
3 3
3 2 2
2 1 1
2 1 1
出力例2
4

Submitted solutions:

code_snippet: // AOJ #2841
// Indecision 2025.2.5

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int N, C;
    cin >> N >> C;
    vector<int> a(N), b(N), cost(N);
    for (int i = 0; i < N; i++){
        cin >> a[i] >> b[i] >> cost[i];
    }
    
    const int MAX_D = 99 * 100;
    int offset = MAX_D;
    int diffSize = 2 * MAX_D + 1;
    
    vector<vector<int>> dp(C+1, vector<int>(diffSize, -1));
    dp[0][offset] = 0;
    
    for (int i = 0; i < N; i++){
        int cst = cost[i];
        int d = a[i] - b[i];
        int val = a[i] + b[i];
        for (int curCost = C - cst; curCost >= 0; curCost--){
            for (int diffIdx = 0; diffIdx < diffSize; diffIdx++){
                if(dp[curCost][diffIdx] < 0) continue;
                int newCost = curCost + cst;
                int newDiffIdx = diffIdx + d;
                if(newDiffIdx < diffSize){
                    dp[newCost][newDiffIdx] = max(dp[newCost][newDiffIdx], dp[curCost][diffIdx] + val);
                }
                newDiffIdx = diffIdx - d;
                if(newDiffIdx >= 0){
                    dp[newCost][newDiffIdx] = max(dp[newCost][newDiffIdx], dp[curCost][diffIdx] + val);
                }
            }
        }
    }
    
    int ans = 0;
    for (int curCost = 0; curCost <= C; curCost++){
        for (int diffIdx = 0; diffIdx < diffSize; diffIdx++){
            if(dp[curCost][diffIdx] < 0) continue;
            int total = dp[curCost][diffIdx];
            int imbalance = abs(diffIdx - offset);
            int candidate = (total - imbalance) / 2;
            ans = max(ans, candidate);
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 10996
final_rank: 6

code_snippet: // AOJ #2841
// Indecision 2025.2.5

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int N, C;
    cin >> N >> C;
    vector<int> a(N), b(N), cost(N);
    for (int i = 0; i < N; i++){
        cin >> a[i] >> b[i] >> cost[i];
    }
    
    const int MAX_D = 99 * 100;
    int offset = MAX_D;
    int diffSize = 2 * MAX_D + 1;
    
    vector<vector<int>> dp(C+1, vector<int>(diffSize, -1));
    dp[0][offset] = 0;
    
    for (int i = 0; i < N; i++){
        int cst = cost[i];
        int d = a[i] - b[i];
        int val = a[i] + b[i];
        for (int curCost = C - cst; curCost >= 0; curCost--){
            for (int diffIdx = 0; diffIdx < diffSize; diffIdx++){
                if(dp[curCost][diffIdx] < 0) continue;
                int newCost = curCost + cst;
                int newDiffIdx = diffIdx + d;
                if(newDiffIdx < diffSize){
                    dp[newCost][newDiffIdx] = max(dp[newCost][newDiffIdx], dp[curCost][diffIdx] + val);
                }
                newDiffIdx = diffIdx - d;
                if(newDiffIdx >= 0){
                    dp[newCost][newDiffIdx] = max(dp[newCost][newDiffIdx], dp[curCost][diffIdx] + val);
                }
            }
        }
    }
    
    int ans = 0;
    for (int curCost = 0; curCost <= C; curCost++){
        for (int diffIdx = 0; diffIdx < diffSize; diffIdx++){
            if(dp[curCost][diffIdx] < 0) continue;
            int total = dp[curCost][diffIdx];
            int imbalance = abs(diffIdx - offset);
            int candidate = (total - imbalance) / 2;
            ans = max(ans, candidate);
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 11028
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=1e9+7;
#define rep(i,a) for (int i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}


void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,C;
	cin>>N>>C;
	vector<vector<int>> dp(C+1,vector<int>((N+1)*101,-INF));
	dp[0][0]=0;
	rep(i,N){
		int a,b,c;
		cin>>a>>b>>c;
		for(int j=C-c;j>=0;j--) rep(k,(i+1)*101){
			chmax(dp[j+c][k+a],dp[j][k]+b);
			chmax(dp[j+c][k+b],dp[j][k]+a);
		}
	}
	int ans=0;
	rep(i,C+1) rep(j,(N+1)*101){
		chmax(ans,min(j,dp[i][j]));
	}
	cout<<ans<<"\n";
}
accuracy: 1
time_ms: 70
memory_kb: 7300
final_rank: 3

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
 
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#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 MOD 1000000007
 
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-8, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< 1000000007 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
 
  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
 
  inline T fact(int k) const { return _fact[k]; }
 
  inline T rfact(int k) const { return _rfact[k]; }
 
  inline T inv(int k) const { return _inv[k]; }
 
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }
 
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
 
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
 
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  if(x == 0) return 0;
  while(n) {
    if(n&1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
template<typename T> 
struct BIT{
  int N;
  std::vector<T> node;
  BIT(){}
  BIT(int n){
    N = n;
    node.resize(N+10);
  }
  void build(int n) {
    N = n;
    node.resize(N+10);
  }
  /* a: 1-indexed */
  void add(int a, T x){
    for(int i=a; i<(int)node.size(); i += i & -i) node[i] += x;
  }

  /* [1, a] */
  T sum(int a){
    T res = 0;
    for(int x=a; x>0; x -= x & -x) res += node[x];
    return res;
  }

  /* [l, r] */
  T rangesum(int l, int r){
    return sum(r) - sum(l-1);
  }

  /* 
    a1+a2+...+aw >= valとなるような最小のwを返す
    @verify https://codeforces.com/contest/992/problem/E
  */
  int lower_bound(T val) {
    if(val < 0) return 0;

    int res = 0;
    int n = 1; 
    while (n < N) n *= 2;

    T tv=0;
    for (int k = n; k > 0; k /= 2) {
      if(res + k < N && node[res + k] < val){
        val -= node[res+k];
        res += k;
      }
    }
    return res+1; 
  }
};
struct UnionFind{
  std::vector<int> par;
  std::vector<int> siz;

  UnionFind(int sz_): par(sz_), siz(sz_) {
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  void init(int sz_){
    par.resize(sz_);
    siz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  int root(int x){
    if(x == par[x]) return x;
    return par[x] = root(par[x]);
  }

  bool merge(int x, int y){
    x = root(x), y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) std::swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return siz[root(x)];
  }
};
struct RollingHash{

    using ull = unsigned long long;
    const ull mod = (1ULL << 61) - 1;
    const ull MASK30 = (1ULL << 30) - 1;
    const ull MASK31 = (1ULL << 31) - 1;

    const ull MASK61 = mod;

    ull base;
    int n;
    vector<ull> hash, pow;

    RollingHash(const string &s)
    {
        random_device rnd;
        mt19937_64 mt(rnd());
        base = 1001;
        
        n = (int)s.size();
        hash.assign(n+1, 0);
        pow.assign(n+1, 1);
        
        for(int i=0; i<n; i++){
            hash[i+1] = calc_mod(mul(hash[i], base) + s[i]);
            pow[i+1] = calc_mod(mul(pow[i], base));
        }
    }

    ull calc_mod(ull x){
        ull xu = x >> 61;
        ull xd = x & MASK61;
        ull res = xu + xd;
        if(res >= mod) res -= mod;
        return res;
    }

    ull mul(ull a, ull b){
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30;
        ull midd = mid & MASK30;
        return calc_mod(au * bu * 2 + midu + (midd << 31) + ad * bd);
    }

    //[l,r)のハッシュ値
    inline ull get(int l, int r){
        ull res = calc_mod(hash[r] + mod*3-mul(hash[l], pow[r-l]));
        return res;
    }
    //string tのハッシュ値
    inline ull get(string t){
        ull res = 0;
        for(int i=0; i<t.size(); i++){
            res = calc_mod(mul(res, base)+t[i]);
        }
        return res;
    }
    //string s中のtの数をカウント
    inline int count(string t) {
        if(t.size() > n) return 0;
        auto hs = get(t);
        int res = 0;
        for(int i=0; i<n-t.size()+1; i++){
            if(get(i, i+t.size()) == hs) res++; 
        }
        return res;
    }

    /* 
        concat 
        @verify https://codeforces.com/problemset/problem/514/C
    */
    inline ull concat(ull h1, ull h2, int h2len){
      return calc_mod(h2 + mul(h1, pow[h2len]));
    }

    // LCPを求める S[a:] T[b:]
    inline int LCP(int a, int b){
        int len = min((int)hash.size()-a, (int)hash.size()-b);
        
        int lb = -1, ub = len;
        while(ub-lb>1){
            int mid = (lb+ub)/2;

            if(get(a, a+mid) == get(b, b+mid)) lb = mid;
            else ub = mid;
        }
        return lb;
    }
};
int dp[110][10100];
int main() {  
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int n, C; cin >> n >> C;
  REP(i,110) REP(j,10100) dp[i][j] = -1;
  dp[0][0] = 0;
  for(int i=0; i<n; i++) {
    int a, b, c; cin >> a >> b >> c;
    for(int j=C; j>=0; j--) {
      if(j+c<=C) {
        for(int k=10000; k>=0; k--) {
          if(dp[j][k] == -1) continue;
          if(k+a<=10000)dp[j+c][k+a] = max(dp[j+c][k+a], dp[j][k] + b);
          if(k+b<=10000)dp[j+c][k+b] = max(dp[j+c][k+b], dp[j][k] + a);
        }
      }
    }
  }
  int ans = 0;
  REP(i,C+1) {
    REP(j,10001) ans = max(ans, min(j, dp[i][j]));
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 7796
final_rank: 2

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>


int main() {
	int n, budget; std::cin >> n >> budget;
	std::vector<std::tuple<int, int, int>> events(n);
	for (auto& [a, b, c] : events) {
		std::cin >> a >> b >> c;
	}
	std::vector<std::vector<int>> max_sum(budget + 1, std::vector<int>(10001, 0));
	std::vector<std::vector<int>> used(budget + 1);
	used[budget].push_back(0);
	for (const auto [a, b, c] : events) {
		const auto d = a - b;
		const auto s = a + b;
		for (auto rest = c; rest <= budget; ++rest) {
			for (const auto diff : used[rest]) {
				if (max_sum[rest - c][diff + d] < max_sum[rest][diff] + s) {
					if (max_sum[rest - c][diff + d] == 0) {
						used[rest - c].push_back(diff + d);
					}
					max_sum[rest - c][diff + d] = max_sum[rest][diff] + s;
				}
				const auto nd = std::abs(diff - d);
				if (max_sum[rest - c][nd] < max_sum[rest][diff] + s) {
					if (max_sum[rest - c][nd] == 0) {
						used[rest - c].push_back(nd);
					}
					max_sum[rest - c][nd] = max_sum[rest][diff] + s;
				}
			}
		}
	}
	int result{ 0 };
	for (const auto& line : max_sum) {
		for (auto diff = 0; diff < line.size(); ++diff) {
			if (line[diff] == 0) continue;
			const auto sum = line[diff];
			result = std::max(result, sum - diff);
		}
	}
	std::cout << (result >> 1) << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 7756
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
const ll LINF = 0x1fffffffffffffff;
#define name3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) name3(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define each(i,a) for(auto &i : a)
#define sum(a) accumulate(all(a), 0LL)
#define all(i) begin(i), end(i)
template<class T, class U> inline bool chmin(T &a, const U &b){ if(a > b) { a = b; return 1; } else return 0; }
template<class T, class U> inline bool chmax(T &a, const U &b){ if(a < b) { a = b; return 1; } else return 0; }


int main(){
    ll n, C;
    cin >> n >> C;
    vector<vector<ll>>dp(C+1, vector<ll>(10001,-LINF));
    dp[0][0]=0;
    rep(n){
        ll a, b, c;
        cin >> a >> b >> c;
        rrep(i,c,C+1){
            rep(j,a,10001)chmax(dp[i][j],dp[i-c][j-a]+b);
            rep(j,b,10001)chmax(dp[i][j],dp[i-c][j-b]+a);
        }
    }
    ll ans=0;
    rep(C+1)rep(j,10001)chmax(ans,min(j,dp[i][j]));
    cout << ans << endl;
}
accuracy: 1
time_ms: 170
memory_kb: 10804
final_rank: 10

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long long INF=1152921504606846976;
const long double PI=3.1415926535897932;

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define umap unordered_map
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())

//最大公約数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

//最小公倍数
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename Num>
constexpr Num mypow(Num a,ll b){
    if(b==0)return 1;
    if(a==0)return 0;
    Num x=1;
    while(b>0){
        if(b&1)x*=a;
        a*=a;
        b>>=1;
        }
    return x;
}

//chmin,chmax
template<class T>
inline bool chmin(T& a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmax(T& a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

//MODint
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }

    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x){
        long long t;
        is >> t;
        x=t;
        return (is);
    }

    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD1>;

//start
    signed main(){
        ll n,maxc;
        cin>>n>>maxc;
        vl A(n+1),B(n+1),C(n+1);
        A[0] = 0;B[0] = 0;C[0] = 0;
        rep(i,n)cin>>A[i+1]>>B[i+1]>>C[i+1];
        vector<vvl> DP(n+1,vvl(maxc+1,vl(10100,0)));
        rep2(i,1,n+1){
            rep2(j,0,maxc+1){
                rep2(k,1,10001){
                    chmax(DP[i][j][k],DP[i-1][j][k]);
                    if(j-C[i]<0)continue;
                    if(!k-A[i]<0)chmax(DP[i][j][k],DP[i-1][j-C[i]][k-A[i]]+B[i]);
                    if(!k-B[i]<0)chmax(DP[i][j][k],DP[i-1][j-C[i]][k-B[i]]+A[i]);
                }
            }
        }
        ll res=0;
        rep(i,maxc){
            rep(j,10001){
                ll po=min(j,DP[n][i][j]);
                chmax(res,po);
            }
        }
        cout<<res<<endl;
    }
accuracy: 0.045454545454545456
time_ms: 20
memory_kb: 43184
final_rank: 20

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long long INF=1152921504606846976;
const long double PI=3.1415926535897932;

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define umap unordered_map
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())

//最大公約数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

//最小公倍数
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename Num>
constexpr Num mypow(Num a,ll b){
    if(b==0)return 1;
    if(a==0)return 0;
    Num x=1;
    while(b>0){
        if(b&1)x*=a;
        a*=a;
        b>>=1;
        }
    return x;
}

//chmin,chmax
template<class T>
inline bool chmin(T& a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmax(T& a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

//MODint
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }

    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x){
        long long t;
        is >> t;
        x=t;
        return (is);
    }

    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD1>;

//start
    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n,maxc;
        cin>>n>>maxc;
        vl A(n),B(n),C(n);
        rep(i,n)cin>>A[i]>>B[i]>>C[i];
        vector<vvl> DP(n+1,vvl(maxc+1,vl(10100,0)));
        rep2(i,1,n+1){
            rep2(j,0,maxc+1){
                rep2(k,1,10001){
                    chmax(DP[i][j][k],DP[i-1][j][k]);
                    if(j-C[i-1]<0)continue;
                    if(!k-A[i-1]<0)chmax(DP[i][j][k],DP[i-1][j-C[i-1]][k-A[i-1]]+B[i-1]);
                    if(!k-B[i-1]<0)chmax(DP[i][j][k],DP[i-1][j-C[i-1]][k-B[i-1]]+A[i-1]);
                }
            }
        }
        ll res=0;
        rep(i,maxc){
            rep(j,10001){
                ll po=min(j,DP[n][i][j]);
                chmax(res,po);
            }
        }
        cout<<res<<endl;
    }
accuracy: 0.045454545454545456
time_ms: 10
memory_kb: 43172
final_rank: 19

code_snippet: #include <bits/stdc++.h>
// aya_seは起床のプロ
using namespace std;

//@ebi's definition

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n - 1)); i >= (int)(a); i--)
#define all(v) (v).begin(), (v).end()

using ll = long long;

struct Edge
{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w) {}
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<ll>>;

// xxpoxx's definition
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const int INF = 1e9+7;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/

// aya_se's definition
vl fac, finv, inv;
void COMinit(ll N)
{
    fac.resize(N);
    finv.resize(N);
    inv.resize(N);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < N; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,c; cin >> n >> c;
    vector<vector<int>> a(n,vector<int>(3));
    int s = 0;
    rep(i,0,n){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        s += a[i][0];
    }
    vector<map<int,int>> dp(c+1);
    dp[0][0] = 0;
    rep(i,0,n){
        rrep(j,0,c){
            for(auto x : dp[j]){
                int k = x.first;
                if(x.second<0){
                    continue;
                }
                int p = min(k+a[i][0],x.second+a[i][1]);
                int q = max(k+a[i][0],x.second+a[i][1]);
                int r = k+a[i][1];
                int t = x.second+a[i][0];
                if(j+a[i][2]<=c){
                    chmax(dp[j+a[i][2]][p],q);
                    chmax(dp[j+a[i][2]][r],t);
                }
            }
        }
    }
    int ans = -1;
    rep(i,0,c+1){
        for(auto x: dp[i]){
            if(x.second<0){
                continue;
            }
            chmax(ans,x.first);
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 810
memory_kb: 12412
final_rank: 15

code_snippet: #include <bits/stdc++.h>
// aya_seは起床のプロ
using namespace std;

//@ebi's definition

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n - 1)); i >= (int)(a); i--)
#define all(v) (v).begin(), (v).end()

using ll = long long;

struct Edge
{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w) {}
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<ll>>;

// xxpoxx's definition
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const int INF = 1e9+7;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/

// aya_se's definition
vl fac, finv, inv;
void COMinit(ll N)
{
    fac.resize(N);
    finv.resize(N);
    inv.resize(N);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < N; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,c; cin >> n >> c;
    vector<vector<int>> a(n,vector<int>(3));
    int s = 0;
    rep(i,0,n){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        s += a[i][0];
    }
    int m = s*n;
    vector<vector<int>> dp(c+1,vector<int>(m+1,-1));
    vector<int> fs(c+1,INF);
    vector<int> sc(c+1,-1);
    dp[0][0] = 0;
    fs[0] = 0;
    sc[0] = 0;
    rep(i,0,n){
        rrep(j,0,c){
            rep(k,fs[j],sc[j]+1){
                if(dp[j][k]<0){
                    continue;
                }
                int p = min(k+a[i][0],dp[j][k]+a[i][1]);
                int q = max(k+a[i][0],dp[j][k]+a[i][1]);
                if(j+a[i][2]<=c){
                    chmax(dp[j+a[i][2]][p],q);
                    chmin(fs[j+a[i][2]],p);
                    chmax(sc[j+a[i][2]],p);
                }
            }
        }
    }
    int ans = -1;
    rep(i,0,c+1){
        rep(j,0,m){
            if(dp[i][j]>0){
                chmax(ans,j);
            }
        }
    }
    cout << ans << endl;
}
accuracy: 0.06818181818181818
time_ms: 100
memory_kb: 252192
final_rank: 18

code_snippet: #include<iostream>
#include<vector>

using ll = int;
using namespace std;

int main(){
    ll n,cost;
    cin >> n >> cost;
    vector<vector<ll>> dp(10001,vector<ll>(cost+1,-1));
    dp.at(0).at(0) = 0;

    for(ll i=0; i<n; i++){
        ll a,b,c;
        cin >> a >> b >> c;
        for(ll j=10000; j>=0; j--){
            for(ll k=cost; k>=0; k--){
                if(dp.at(j).at(k) == -1) continue;
                if(k+c > cost)continue;
                if(j+a <= 10000) dp.at(j+a).at(k+c) = max(dp.at(j+a).at(k+c), dp.at(j).at(k) + b);
                if(j+b <= 10000) dp.at(j+b).at(k+c) = max(dp.at(j+b).at(k+c), dp.at(j).at(k) + a);
            }
        }
    }
    ll ans = -1;
    for(ll j = 0; j<10001; j++){
        for(ll k=0; k<cost+1; k++){
            ans = max(ans, min(j, dp.at(j).at(k)));
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 100
memory_kb: 7108
final_rank: 5

code_snippet: #include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
constexpr ll INF = 1ll<<30;
constexpr ll MOD = 1000000007;
//---------------------------------//

int main() {
	int N, C;
	cin >> N >> C;
	vector<int> a(N), b(N), c(N);
	REP(i, N) scanf("%d %d %d", &a[i], &b[i], &c[i]);
	
	vector<vector<vector<int>>> dp(2, vector<vector<int>>(101, vector<int>(10001, INF)));
	
	dp[0][0][0] = 0;
	REP(i, N) {
		int cur = i & 1;
		int nex = cur ^ 1;
		REP(j, C + 1) REP(k, 10001) dp[nex][j][k] = INF;
		
		REP(j, C + 1) REP(k, 10001) {
			if (dp[cur][j][k] == INF) continue;
			if (j + c[i] <= C) {
				REP(t, 2) {
					int ka = max(k + a[i], k - dp[cur][j][k] + b[i]), kb = min(k + a[i], k - dp[cur][j][k] + b[i]);
					chmin(dp[nex][j + c[i]][ka], ka - kb);
					swap(a[i], b[i]);
				}
			}
			chmin(dp[nex][j][k], dp[cur][j][k]);
		}
	}
	int ans = 0;
	REP(j, C + 1) REP(k, 10001) {
		if (dp[N & 1][j][k] == INF) continue;
		chmax(ans, k - dp[N & 1][j][k]);
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 14824
final_rank: 11

code_snippet: #include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using usize = std::size_t;
using isize = std::ptrdiff_t;
using u64 = std::uint64_t;

static constexpr u64 mod = 1000000007;

template <class T> void chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
  }
}

int main() {
  usize n, cc;
  std::cin >> n >> cc;
  static constexpr usize C = 100;
  static constexpr usize A = 10000;

  std::array<std::array<isize, A + 1>, C + 1> dp;
  for (auto &v : dp) {
    std::fill(v.begin(), v.end(), std::numeric_limits<isize>::min());
  }
  dp[0][0] = 0;
  for (usize nn = 0; nn != n; ++nn) {
    usize a, b, c;
    std::cin >> a >> b >> c;
    for (usize i = C + 1; i-- != 0;) {
      for (usize j = 0; j <= A; ++j) {
        if (i >= c && j >= a) {
          chmax<isize>(dp[i][j], dp[i - c][j - a] + b);
        }
        if (i >= c && j >= b) {
          chmax<isize>(dp[i][j], dp[i - c][j - b] + a);
        }
      }
    }
  }

  usize ans = 0;
  for (usize i = 0; i <= C; ++i) {
    for (usize j = 0; j <= A; ++j) {
      if (i <= cc && dp[i][j] >= 0) {
        chmax(ans, std::min<usize>(j, dp[i][j]));
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 10992
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
const ll LINF = 0x1fffffffffffffff;
#define name3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) name3(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define each(i,a) for(auto &i : a)
#define sum(a) accumulate(all(a), 0LL)
#define all(i) begin(i), end(i)
template<class T, class U> inline bool chmin(T &a, const U &b){ if(a > b) { a = b; return 1; } else return 0; }
template<class T, class U> inline bool chmax(T &a, const U &b){ if(a < b) { a = b; return 1; } else return 0; }


int main(){
    ll n, C;
    cin >> n >> C;
    vector<vector<ll>>dp(C+1, vector<ll>(10001,-LINF));
    dp[0][0]=0;
    rep(n){
        ll a, b, c;
        cin >> a >> b >> c;
        rrep(i,c,C+1){
            rep(j,a,10001)chmax(dp[i][j],dp[i-c][j-a]+b);
            rep(j,b,10001)chmax(dp[i][j],dp[i-c][j-b]+a);
        }
    }
    ll ans=0;
    rep(C+1)rep(j,10001)chmax(ans,min(j,dp[i][j]));
    cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 10804
final_rank: 12

code_snippet: #include <iostream>
#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 <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int dp[2][100 + 1][100 * 100 + 1] = {};

int main() {
  
  int n, C; cin >> n >> C;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 100 + 1; j++) {
      for (int k = 0; k < 100 * 100 + 1; k++) {
        dp[i][j][k] = -1;
      }
    }
  }

  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);

  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }

  // dp[i][費用][メインのヒロインの好感度] := サブヒロインの好感度の max
  dp[0][0][0] = 0;
  int cur = 0;
  int nxt = 1;

  int likeMax = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= C; j++) {
      for (int k = 0; k <= likeMax; k++) {
        if (dp[cur][j][k] == -1) continue;

        // 取らない
        dp[nxt][j][k] = max(dp[nxt][j][k], dp[cur][j][k]);

        // 普通にとる
        if (j + c[i] <= C) {
          chmax(dp[nxt][j + c[i]][k + a[i]], dp[cur][j][k] + b[i]);
        }

        // 逆でとる
        if (j + c[i] <= C) {
          chmax(dp[nxt][j + c[i]][k + b[i]], dp[cur][j][k] + a[i]);
        }
      }
    }

    likeMax += max(a[i], b[i]);
    swap(cur, nxt);
  }

  int ans = 0;
  for (int j = 0; j <= C; j++) {
    for (int k = 0; k <= likeMax; k++) {
      ans = max(ans, min(k, dp[cur][j][k]));
    }
  }

  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 10992
final_rank: 4

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

int dp[2][10100][110];

int main(){
    int N,C;
    cin >> N >> C;
    vector<int> a(N),b(N),c(N);
    for(int i=0; i<N; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i=0; i<2; i++){
        for(int j=0; j<10100; j++){
            for(int k=0; k<110; k++){
                dp[i][j][k] = -1;
            }
        }
    }
    dp[0][0][0] = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<10100; j++){
            for(int k=0; k<=C; k++){
                if(dp[i%2][j][k] == -1) continue;
                dp[(i+1)%2][j][k] = max(dp[(i+1)%2][j][k],dp[i%2][j][k]);
                if(k + c[i] > C) continue;
                int now = dp[i%2][j][k];
                int nxt = min(10010,j+b[i]);
                dp[(i+1)%2][nxt][k+c[i]] = max(dp[(i+1)%2][nxt][k+c[i]],now+a[i]);
                if(j+a[i] > now+b[i]){
                    int nxt2 = min(10010,now+b[i]);
                    dp[(i+1)%2][nxt2][k+c[i]] = max(dp[(i+1)%2][nxt2][k+c[i]],j+a[i]);
                }else{
                    int nxt2 = min(10010,j+a[i]);
                    dp[(i+1)%2][nxt2][k+c[i]] = max(dp[(i+1)%2][nxt2][k+c[i]],now+b[i]);
                }
                dp[i%2][j][k] = -1;
            }
        }
    }
    int ans = -1;
    for(int j=0; j<10010; j++){
        for(int k=0; k<=C; k++){
            if(dp[N%2][j][k] != -1){
                ans = max(ans,j);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 11780
final_rank: 8

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

int dp[110][1010][110];

int main(){
    int N,C;
    cin >> N >> C;
    vector<int> a(N),b(N),c(N);
    for(int i=0; i<N; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i=0; i<110; i++){
        for(int j=0; j<1010; j++){
            for(int k=0; k<110; k++){
                dp[i][j][k] = -1;
            }
        }
    }
    dp[0][0][0] = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<1010; j++){
            for(int k=0; k<=C; k++){
                if(dp[i][j][k] == -1) continue;
                dp[i+1][j][k] = max(dp[i+1][j][k],dp[i][j][k]);
                if(k + c[i] > C) continue;
                int now = dp[i][j][k];
                int nxt = min(1000,j+b[i]);
                dp[i+1][nxt][k+c[i]] = max(dp[i+1][nxt][k+c[i]],now+a[i]);
                if(j+a[i] > now+b[i]){
                    int nxt2 = min(1000,now+b[i]);
                    dp[i+1][nxt2][k+c[i]] = max(dp[i+1][nxt2][k+c[i]],j+a[i]);
                }else{
                    int nxt2 = min(1000,j+a[i]);
                    dp[i+1][nxt2][k+c[i]] = max(dp[i+1][nxt2][k+c[i]],now+b[i]);
                }
            }
        }
    }
    int ans = -1;
    for(int j=0; j<1010; j++){
        for(int k=0; k<=C; k++){
            if(dp[N][j][k] != -1){
                ans = max(ans,j);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
accuracy: 0.5
time_ms: 30
memory_kb: 50832
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,t;cin >> n >> t;
    vector<int> a(n),b(n),c(n);
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<vector<int>> dp(100001,vector<int>(t+1,-1));
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        vector<vector<int>> tp(100001,vector<int>(t+1,-1));
        for(int j=0;j<=10000;j++){
            for(int k=0;k<=t;k++){
                if(dp[j][k]==-1){
                    continue;
                }
                chmax(tp[j][k],dp[j][k]);
                if(k+c[i]<=t){
                    int u=dp[j][k],v=dp[j][k]-j;
                    int p=max(u+a[i],v+b[i]),q=min(u+a[i],v+b[i]);
                    chmax(tp[p-q][k+c[i]],p);
                    p=max(u+b[i],v+a[i]),q=min(u+b[i],v+a[i]);
                    chmax(tp[p-q][k+c[i]],p);
                }
            }
        }
        for(int j=0;j<=10000;j++){
            for(int k=0;k<=t;k++){
                dp[j][k]=tp[j][k];
            }
        }
    }
    int ans=0;
    for(int i=0;i<=10000;i++){
        for(int j=0;j<=t;j++){
            chmax(ans,dp[i][j]-i);
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 1740
memory_kb: 88956
final_rank: 16

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

int DP[2][101][11000];

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);
    int n, c;
    cin >> n >> c;
    vector<int> A(n), B(n), C(n);
    for (int i = 0; i < n; i++){
        cin >> A[i] >> B[i] >> C[i];
    }

    const int INF = 1e9;
    for (int j = 0; j <= c; j++){
        for (int k = 0; k <= 10000; k++){
            DP[0][j][k] = -INF;
        }
    }

    DP[0][c][0] = 0;

    for (int i = 0; i < n; i++){
        for (int j = 0; j <= c; j++){
        for (int k = 0; k <= 10000; k++){
            DP[(i + 1) & 1][j][k] = -INF;
        }}
        DP[(i + 1) & 1][c][0] = 0;
        for (int j = 0; j <= c; j++){
            for (int k = 0; k <= 10000; k++){
                DP[(i + 1) & 1][j][k] = DP[i & 1][j][k];
                if (j - C[i] >= 0){
                    DP[(i + 1) & 1][j - C[i]][k + A[i]] = max(DP[(i + 1) & 1][j - C[i]][k + A[i]], DP[i & 1][j][k] + B[i]);
                    DP[(i + 1) & 1][j - C[i]][k + B[i]] = max(DP[(i + 1) & 1][j - C[i]][k + B[i]], DP[i & 1][j][k] + A[i]);
                }
            }
        }
    }


    int ans = 0;
    for (int i = 0; i <= c; i++){
        for (int j = 0; j <= 10000; j++){
            if (j <= DP[n & 1][i][j])
                ans = max(ans, j);
        }
    }

    cout << ans << endl;
}
accuracy: 1
time_ms: 270
memory_kb: 11836
final_rank: 14

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

struct aa {
	int a;
	int b;
	int cost;
};

int main()
{
	int N,C;cin>>N>>C;
	vector<aa>dates;
	for (int i = 0; i < N; ++i) {
		int a,b,c;cin>>a>>b>>c;
		dates.push_back(aa{ a,b,c });
	}
	vector<vector<vector<int>>>dp(2,vector<vector<int>>(100*N+1,vector<int>(C+1,-1e9)));

	dp[0][0][0]=0;
	for (int i = 0; i < N; ++i) {
		int now(i%2);
		int nex(1&(i-1));

		for (int a_love = 0; a_love <= 100*i; ++a_love) {
			for (int money = 0; money <= C; ++money) {
				dp[nex][a_love][money]=max(dp[nex][a_love][money],dp[now][a_love][money]);

				{
					const int next_money=money+dates[i].cost;
					if (next_money <= C) {
						dp[nex][a_love+dates[i].a][next_money]=max(dp[nex][a_love+dates[i].a][next_money],dp[now][a_love][money]+dates[i].b);
						dp[nex][a_love+dates[i].b][next_money]=max(dp[nex][a_love+dates[i].b][next_money],dp[now][a_love][money]+dates[i].a);
					}
				}
			}
		}
	}


	int ans=0;
	for (int i = 0; i < 100 * N + 1; ++i) {
		for (int money = 0; money <= C; ++money) {
			ans=max(ans,min(i,dp[N%2][i][money]));
			
		}
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 15808
final_rank: 13