#include typedef long long ll; typedef unsigned long long ull; using namespace std; #define pb push_back int dy[]={0, 0, 1, -1, 1, 1, -1, -1}; int dx[]={1, -1, 0, 0, 1, -1, -1, 1}; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define mp make_pair #define fi first #define sc second #define INF (1e9) int W,N,K; int A[100],B[100]; int dp[51][10001][51]; int main(){ cin >> W >> N >> K; REP(i,N) { cin >> A[i] >> B[i]; } REP(i,W + 1) { REP(j,K + 1) { dp[0][i][j] = 0; } } FOR(i,1,N + 1) { REP(j,W + 1) { REP(k,K + 1) { if(0 <= j - A[i - 1] && 0 <= k - 1) dp[i][j][k] = max(dp[i - 1][j][k],dp[i - 1][j - A[i - 1]][k - 1] + B[i - 1]); else dp[i][j][k] = dp[i - 1][j][k]; } } } cout << dp[N][W][K] << endl; return 0; }