Language: C++

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 10005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n, m, a[maxn], b[maxn], dp[maxn], ans = inf, Ma = inf, id = inf;
signed main() {
	n = read(), m = read(), mem(dp, 63), dp[0] = 0;
	rep(i, 1, m) {
		a[i] = read(), b[i] = read();
		if(b[i] <= Ma) Ma = b[i];
	}
	rep(i, 1, m) if(b[i] == Ma) id = min(id, a[i]);
	for(re int i = 1; i <= m; ++ i) {
		for(re int j = a[i]; j <= n; ++ j) {
			dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
		}
	}
	rep(j, max(n - id, 0), n - 1) ans = min(ans, dp[j] + Ma);
	cout << min(dp[n], ans);
	return 0;
}

Compiler output:
a.cc: In function 'long long int read()':
a.cc:12:12: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     re int x = 0, f = 1; re char c = getchar();
      |            ^
a.cc:12:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     re int x = 0, f = 1; re char c = getchar();
      |                   ^
a.cc:12:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 |     re int x = 0, f = 1; re char c = getchar();
      |                                  ^
a.cc: In function 'int main()':
a.cc:37:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   37 |         for(re int i = 1; i <= m; ++ i) {
      |                    ^
a.cc:38:28: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   38 |                 for(re int j = a[i]; j <= n; ++ j) {
      |                            ^
a.cc:42:19: error: no matching function for call to 'max(long long int, int)'
   42 |         rep(j, max(n - id, 0), n - 1) ans = min(ans, dp[j] + Ma);
      |                ~~~^~~~~~~~~~~
a.cc:17:37: note: in definition of macro 'rep'
   17 | #define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
      |                                     ^
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:42:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   42 |         rep(j, max(n - id, 0), n - 1) ans = min(ans, dp[j] + Ma);
      |                ~~~^~~~~~~~~~~
a.cc:17:37: note: in definition of macro 'rep'
   17 | #define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
      |                                     ^
/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:42:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   42 |         rep(j, max(n - id, 0), n - 1) ans = min(ans, dp[j] + Ma);
      |                ~~~^~~~~~~~~~~
a.cc:17:37: note: in definition of macro 'rep'
   17 | #define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
      |                                     ^
a.cc:42:13: error: 'jLimit' was not declared in this scope
   42 |         rep(j, max(n - id, 0), n - 1) ans = min(ans, dp[j] + Ma);
      |             ^
a.cc:17:64: note: in definition of macro 'rep'
   17 | #define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
      |                                                                ^