Time Limit: 1000MS |
Memory Limit: 65535KB |
Submissions: 512 |
Accepted: 178 |
Sample Input
15 6
1 2
1 6
4 11
8 5
8 1
11 5
Sample Output
4
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int p[10005][20], dp[10005];
int Time, N;
int s, len;
while(cin>>Time>>N)
{
memset(p, 0, sizeof(p));
memset(dp, 0, sizeof(dp));
for (int i = 0; i < N; i++)
{
cin>>s>>len;
p[s][0]++;
p[s][p[s][0]] = len;
}
for (int i = Time; i >= 1; i--)
{
if (p[i][0] == 0)
{
dp[i] = dp[i + 1] + 1;
}
else
if (p[i][0] == 1)
{
dp[i] = max(dp[i + p[i][1]], dp[i]);
}
else
{
for (int j = 1; j <= p[i][0]; j++)
{
dp[i] = max(dp[i], dp[i + p[i][j]]);
}
}
}
cout<<dp[1]<<endl;
}
return 0;
}