Language: C++

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
ll T, a[200000], b[200000];

ll A[200000], B[200000];
// 総時間は (((B1)A2+B2)A3+B3)A4+B4 みたいになる

vector<ll> A1;
vector<ll> wa;
vector<pair<double , pair<ll,ll>>> v; // double の値が小さい方が先に選ばれるべき

ll solve(int n, int k){ // 0～n 番目のうちから k 個選ぶ場合の最小時間
    if(n == -1){
        if(k == 0) return 0;
        else return T+1;
    }
    ll ret = min(solve(n-1, k), T+1);
    if(k > 0) ret = min(ret, solve(n-1, k-1)*v[n].second.first+v[n].second.second);
    return ret;
}

signed main(){
    cin >> N >> T;
    rep(i, N) cin >> a[i] >> b[i];

    rep(i, N){
        A[i] = a[i]+1;
        B[i] = a[i]+b[i]+1;
        //cout << A[i] << " " << B[i] << endl;
        if(A[i] == 1) A1.pb(B[i]);
        v.pb({ (double)B[i]/(double)(A[i]-1), {A[i], B[i]} });
    }
    sort(all(A1));
    sort(all(v));
    rep(i, A1.size()) wa.pb((i != 0 ? wa.back() : 0) + A1[i]);

    //rep(i, A1.size()) cout << "1 " << A1[i] << endl;
    //rep(i, v.size()) cout << v[i].second.first << " " << v[i].second.second << " " << v[i].first << endl;
    //rep(i, A1.size()) cout << wa[i] << endl;
    
    int ans = 0;
    rep(i, 30){
        ll t = solve(v.size()-1, i);
        if(t > T) continue;
        ans = max(ans, i + (upper_bound(all(wa), T-t)-wa.begin()));
    }
    cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:18: error: no matching function for call to 'max(int&, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   55 |         ans = max(ans, i + (upper_bound(all(wa), T-t)-wa.begin()));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:55:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   55 |         ans = max(ans, i + (upper_bound(all(wa), T-t)-wa.begin()));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:55:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   55 |         ans = max(ans, i + (upper_bound(all(wa), T-t)-wa.begin()));
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~