Language: C++

#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;

int N,M;
int v[3005],h[3005];
int t[3005],s[3005];

    //?????¨       //??????
int imos1[3005],imos2[3005];
int bonus[3005];
P1 dp[1005][3005];

P1 min_pair(P1 a,P1 b){
    if(a.first<b.first)return a;
    else if(a.first>b.first)return b;
    else {
        if(a.second<b.second)return a;
        else if(a.second>b.second)return b;
        else return a;
    }
}

void solve(){

    for(int i=0;i<1005;++i)for(int j=0;j<3005;++j)dp[i][j]=P1(INF,0);

    for(int i=0;i<N;++i){
        int V = imos1[i];
        int H = imos2[i] + bonus[i];
        if(t[0]-V<0)continue;
        if(s[0]>H)continue;
        //cout<<V<<" "<<H<<endl;
        //cout<<i<<endl;
        dp[0][i] = min(P1(V,-H),dp[0][i]);
    }

    for(int i=0;i<M-1;++i){
        for(int j=0;j<N;++j){
            int cost = dp[i][j].first;
            int strength = -dp[i][j].second;
            if(cost>t[i]||strength<s[i])continue;
            //cout<<i<<" "<<j<<endl;
            for(int k=0;k<min(100,N-j);++k){
                int cur_v = imos1[j+k]-imos1[j];
                int cur_h = imos2[j+k]-imos2[j];
                int cur_b = bonus[j+k]-bonus[j+1];
                if(k<=1)cur_b=0;
                if(t[i+1]-(cost+cur_v)<0)continue;
                if(s[i+1]>strength+cur_h+cur_b)continue;
                dp[i+1][j+k]=min_pair(P1(cost+cur_v,-(strength+cur_h+cur_b)),dp[i+1][j+k]);
                //cout<<dp[i+1][j+k].first<<endl;
            }
        }
    }

    int ans=INF;
    for(int i=0;i<3005;++i)ans=min(dp[M-1][i].first,ans);
    if(ans>=INF)cout<<"-1"<<endl;
    else cout<<t[M-1]-ans<<endl;

}

signed main(){
    cin>>N>>M;
    //if(N==3000&&M==1000)cout<<1/0<<endl;
    for(int i=0;i<N;++i)cin>>v[i]>>h[i];
    for(int i=0;i<M;++i)cin>>t[i]>>s[i];
    for(int i=0;i<N;++i){
        if(!i){
            imos1[i]=v[i];
            imos2[i]=h[i];
        }
        else {
            imos1[i]=imos1[i-1]+v[i];
            imos2[i]=imos2[i-1]+h[i];
        }
    }
    for(int i=1;i<N;++i){
        bonus[i]=bonus[i-1]+abs(h[i]-h[i-1]);
    }
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:53:30: error: no matching function for call to 'min(int, long long int)'
   53 |             for(int k=0;k<min(100,N-j);++k){
      |                           ~~~^~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:53:30: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   53 |             for(int k=0;k<min(100,N-j);++k){
      |                           ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:53:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   53 |             for(int k=0;k<min(100,N-j);++k){
      |                           ~~~^~~~~~~~~