#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <functional>
#define s(x,y) sort(x.begin(),x.end(),y);
#define lowbit(x) ((x)&-(x));
using namespace std;
typedef long long ll;
const ll bitwise_max = 33;
ll dp[1010];
struct node
{
ll time, val;
}a;
int main()
{
ll t, m;
scanf("%lld %lld", &t, &m);
while (m--)
{
scanf("%lld %lld", &a.time, &a.val);
for (ll i = t; i >= a.time; i--)
{
dp[i] = max(dp[i], dp[i - a.time] + a.val);
}
}
printf("%lld", dp[t]);
return 0;
}
应该算01背包板题吧。把这题的时间当作背包容量。