bdfz_2024_summer/day13/P1616/P1616.cpp
2024-08-16 10:51:09 +08:00

39 lines
673 B
C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_M=1e4+5;
const int MAX_T=1e7+5;
int T,m;
int t[MAX_M],v[MAX_M];
int dp[MAX_T];
int readint();
signed main(){
T=readint(),m=readint();
for(int i=1;i<=m;i++){
t[i]=readint();
v[i]=readint();
}
for(int i=1;i<=m;i++){
for(int j=t[i];j<=T;j++){
dp[j] = max(dp[j],dp[j-t[i]]+v[i]);
}
}
cout<<dp[T]<<endl;
}
int readint(){
int x=0,w=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}