This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void solve(bool testCases = true) {
    int T = 1;
    if (testCases) cin >> T;
    while (T--) {
        int l, n;
        cin >> l >> n;
        vector<pair<int, pair<int, int>>> v(n);
        for (int i = 0; i < n; i++) {
            int a, b;
            cin >> a >> b;
            v[i] = {i, {a, b}};
        }
        sort(begin(v), end(v),
             [&](pair<int, pair<int, int>> &a, pair<int, pair<int, int>> &b) {
                 return a.second.first < b.second.first;
             });
        vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
        v.insert(begin(v), {-1, {0, INT_MAX}});
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                dp[i][j] = dp[i - 1][j];
            }
            for (int j = 0; j <= i - 1; j++) {
                int tj = v[j].second.first, vj = v[j].second.second;
                int ti = v[i].second.first, vi = v[i].second.second;
                long long int left = vj * (l + ti * vi);
                long long int right = vi * (l + tj * vj);
                if (right > left) {
                    dp[i][j] = max(dp[i][j], 1 + dp[i - 1][j]);
                }
            }
        }
        int answer = 0;
        for (int i = 0; i <= n; i++) {
            answer = max(answer, dp[n][i]);
        }
        cout << answer;
        cout << "\n";
    }
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve(false);
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |