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;
 
#define A first
#define B second
#define MP make_pair
#define ms(a, x) memset(a, x, sizeof(a)) 
 
 
#define boost() ios_base::sync_with_stdio(false); cin.tie(NULL)
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pld;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mxN=2e4+5;
int dp[505][mxN], l, n;
vector <pii> v;
ll solve(int pos, int range){
    if(pos == n)
        return 0;
    if(dp[pos][range] != -1)
        return dp[pos][range];
    ll ret = solve(pos+1, range);
    if(v[pos].B < range)
        ret = max(ret, solve(pos+1, v[pos].B)+1);
    return dp[pos][range]=ret;
}
int main(){
    ms(dp, -1);
    cin >> l >> n;
    for(int i=0; i<n; i++){
        int x, y;
        cin >> x >> y;
        v.push_back({x, l/y + x});
    } 
    sort(v.begin(), v.end());
    cout << solve(0, mxN-5);
}
| # | 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... |