Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
858 B
0
Indexable
Never
 /** In The Name Of God **/
#include <bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back

typedef long long ll;
const int INF = 1e9;
const int maxN = 1e6 + 10;

int t[maxN], x[maxN], y[maxN], dp[maxN];

void solve()
{
    int r, n; cin >> r >> n; r *= 2;
    x[0] = 1; y[0] = 1;
    for (int i=1; i<=n; i++){
        cin >> t[i] >> x[i] >> y[i];
        dp[i] = -INF;
        for (int j=max(i-r, 0); j<i; j++){
            if (abs(x[i] - x[j]) + abs(y[i] - y[j]) <= abs(t[i] - t[j]))
                dp[i] = max(dp[i], dp[j] + 1);
        }
    }
    cout << dp[n];
}
int main()
{
    int t = 1;
    while (t--) solve();
}
 /**
    Life can only be understood backwards;
        but it must be lived forwards;
**/