Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

struct Person {
	int H, P;
	Person(int H, int P) {
		this->H = H;
		this->P = P;
	}
	bool operator< (const Person& a) const {
		if (P == a.P) return H < a.H;
		return P < a.P;
	}
};

int memo[5010]; // minSumH

signed main() {
	int N;
	cin >> N;

	vector<Person> persons;
	rep(i, N) {
		int H, P;
		cin >> H >> P;
		persons.push_back(Person(H, P));
	}
	sort(all(persons));

	const int INF = LLONG_MAX - INT_MAX - 1000000;
	REP(i, 1, 5000) memo[i] = INF;
	rep(i, N) {
		for (int j = 5000; j >= 0; j--) {
			if (memo[j] > persons[i].H) continue;
			memo[j + 1] = min(memo[j + 1], memo[j] + persons[i].P);
		}
	}

	int ret = 0;
	rep(i, 5001) {
		if (memo[i] != INF) ret = i;
	}

	cout << ret << endl;

    return 0;
}
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

struct Person {
	int H, P;
	Person(int H, int P) {
		this->H = H;
		this->P = P;
	}
	bool operator< (const Person& a) const {
		if (P == a.P) return H < a.H;
		return P < a.P;
	}
};

int memo[5010]; // minSumH

signed main() {
	int N;
	cin >> N;

	vector<Person> persons;
	rep(i, N) {
		int H, P;
		cin >> H >> P;
		persons.push_back(Person(H, P));
	}
	sort(all(persons));

	const int INF = LLONG_MAX - INT_MAX - 1000000;
	REP(i, 1, 5000) memo[i] = INF;
	rep(i, N) {
		for (int j = 5000; j >= 0; j--) {
			if (memo[j] > persons[i].H) continue;
			memo[j + 1] = min(memo[j + 1], memo[j] + persons[i].P);
		}
	}

	int ret = 0;
	rep(i, 5001) {
		if (memo[i] != INF) ret = i;
	}

	cout << ret << endl;

    return 0;
}


Compiler output:
a.cc:113:5: error: redefinition of 'long long int dx [4]'
  113 | int dx[4] = { 1, 0, -1, 0 };
      |     ^~
a.cc:31:5: note: 'long long int dx [4]' previously defined here
   31 | int dx[4] = { 1, 0, -1, 0 };
      |     ^~
a.cc:114:5: error: redefinition of 'long long int dy [4]'
  114 | int dy[4] = { 0, -1, 0, 1 };
      |     ^~
a.cc:32:5: note: 'long long int dy [4]' previously defined here
   32 | int dy[4] = { 0, -1, 0, 1 };
      |     ^~
a.cc:116:24: error: redefinition of 'template<class T> void inputVector(std::vector<_Tp>&, long long int)'
  116 | template<class T> void inputVector(vector<T>& v, int n) {
      |                        ^~~~~~~~~~~
a.cc:34:24: note: 'template<class T> void inputVector(std::vector<_Tp>&, long long int)' previously declared here
   34 | template<class T> void inputVector(vector<T>& v, int n) {
      |                        ^~~~~~~~~~~
a.cc:121:8: error: redefinition of 'struct Person'
  121 | struct Person {
      |        ^~~~~~
a.cc:39:8: note: previous definition of 'struct Person'
   39 | struct Person {
      |        ^~~~~~
a.cc:133:5: error: redefinition of 'long long int memo [5010]'
  133 | int memo[5010]; // minSumH
      |     ^~~~
a.cc:51:5: note: 'long long int memo [5010]' previously declared here
   51 | int memo[5010]; // minSumH
      |     ^~~~
a.cc:135:8: error: redefinition of 'int main()'
  135 | signed main() {
      |        ^~~~
a.cc:53:8: note: 'int main()' previously defined here
   53 | signed main() {
      |        ^~~~