Language: C++

#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
#define MAX 10000000
#define MOD 1000000007
 
 
vector<long> fac(MAX);
vector<long> finv(MAX);
vector<long> inv(MAX);
 
//template functions
/////////////////////////
void Cominit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(long i=2;i<MAX;i++){
      fac.at(i)=(fac.at(i-1)*i)%MOD;
      inv.at(i)=MOD-inv.at(MOD%i)*(MOD/i)%MOD;
      finv.at(i)=finv.at(i-1)*inv.at(i)%MOD;
  }
}

long facComb(long N,long M){// nCm%
if(N<M) return 0;
if(N<0||M<0) return 0;
return fac.at(N)*(finv.at(M)*finv.at(N-M)%MOD)%MOD;
}

long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}

long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}

long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}
long maxC(long a,long b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

/////////////////////////


//Answer


int main() {

typedef pair<long,long> P;
long N,T,ans1,ans2,ans;
cin>>N>>T;
vector<long> A(N);
vector<long> B(N);
vector<vector<P>> dp(N+1,vector<P>(T+1));
for(long i=0;i<N;i++){
cin>>A.at(i);
cin>>B.at(i);
}

sort(A.begin(),A.end());

for(long i=0;i<N+1;i++){
    for(long j=0;j<T+1;j++){
        dp.at(i).at(j).first=0;
        dp.at(i).at(j).second=0;
    }
}
for(long i=0;i<N+1;i++){//dp.at(i+1).at(j) i番目までから時間をj以下にするようにして選ぶ
    for(long j=0;j<T+1;j++){
        if(j<A.at(i)){
            dp.at(i+1).at(j).first=dp.at(i).at(j).first;
            dp.at(i+1).at(j).second=maxC(dp.at(i).at(j).second,B.at(i));
        }else{
            if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
                dp.at(i+1).at(j).first=dp.at(i).at(j).first;
                dp.at(i+1).at(j).second=maxC(dp.at(i).at(j).second,B.at(i));
            }else if(dp.at(i).at(j).first<dp.at(i).at(j-A.at(i))+B.at(i)){
                dp.at(i+1).at(j).first=dp.at(i).at(j-A.at(i))+B.at(i);
                dp.at(i+1).at(j).second=dp.at(i).at(j-A.at(i)).second;                
            }else{
                dp.at(i+1).at(j).first=dp.at(i).at(j-A.at(i))+B.at(i);
                dp.at(i+1).at(j).second=maxC(dp.at(i).at(j-A.at(i)).second,maxC(dp.at(i).at(j).second,B.at(i)));                
            }

        }
    }
}
//ans1=dp.at(N).at(T).first;
//ans2=dp.at(N).at(T-1)+dp.at(N).at(T-1).second;

ans=dp.at(N).at(T);
long max=0;
for(long i=0;i<N;i++){
    max=0;
    for(j=i+1;j<N+1;j++){
        if(max<B.at(j)){
            max=B.at(j);
        }
    }
    if(ans<dp.at(i).at(T-1)+max){
        ans=dp.at(i).at(T-1)+max
    }
}

cout<<ans<<endl;


}




Compiler output:
a.cc: In function 'int main()':
a.cc:113:59: error: no match for 'operator+' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long int, long int> >, std::pair<long int, long int> >::value_type' {aka 'std::pair<long int, long int>'} and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
      |                                                |               |
      |                                                |               __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type {aka long int}
      |                                                __gnu_cxx::__alloc_traits<std::allocator<std::pair<long int, long int> >, std::pair<long int, long int> >::value_type {aka std::pair<long int, long int>}
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 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_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:113:66: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'}
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                                                  ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:113:66: note:   mismatched types 'const std::move_iterator<_IteratorL>' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'}
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                                                  ^
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3598 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note:   template argument deduction/substitution failed:
a.cc:113:66: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long int, long int> >, std::pair<long int, long int> >::value_type' {aka 'std::pair<long int, long int>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                                                  ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3616 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note:   template argument deduction/substitution failed:
a.cc:113:66: note:   mismatched types 'const _CharT*' and 'std::pair<long int, long int>'
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                                                  ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note:   template argument deduction/substitution failed:
a.cc:113:66: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'}
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                                                  ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3652 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note:   template argument deduction/substitution failed:
a.cc:113:66: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long int, long int> >, std::pair<long int, long int> >::value_type' {aka 'std::pair<long int, long int>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                                                  ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 3670 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note:   template argument deduction/substitution failed:
a.cc:113:66: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long int, long int> >, std::pair<long int, long int> >::value_type' {aka 'std::pair<long int, long int>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                                                  ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3682 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note:   template argument deduction/substitution failed:
a.cc:113:66: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long int, long int> >, std::pair<long int, long int> >::value_type' {aka 'std::pair<long int, long int>'} is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                                                  ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3689 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note:   template argument deduction/substitution failed:
a.cc:113:66: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long int, long int> >, std::pair<long int, long int> >::value_type' {aka 'std::pair<long int, long int>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                                                  ^
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3696 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note:   template argument deduction/substitution failed:
a.cc:113:66: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long int, long int> >, std::pair<long int, long int> >::value_type' {aka 'std::pair<long int, long int>'} is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  113 |             if(dp.at(i).at(j).first>dp.at(i).at(j-A.at(i))+B.at(i)){
      |                                                                  ^
/usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3719 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note:   template argument deduction/substitution failed:
a.cc