#include <bits/stdc++.h>
using namespace std;
#define e "\n"
#define f first
#define s second
#define ll long long
#define pb push_back
#define pi (3.141592653589)
#define V vector<long long>
#define all(v) v.begin(), v.end()
#define fr(suru,ses) for(int i=suru;i<ses;i++)
const int N=5e3;
const int M=1e4;
ll n,w,k;
ll dp1[N+7][N+7],dp2[N+7][M+7];
vector<pair<ll,ll>>v;
ll recur1(int i,ll fr){
if(fr==0 || i==n)return 0;
if(dp1[i][fr]!=-1)return dp1[i][fr];
return dp1[i][fr]=max(recur1(i+1,fr-1)+v[i].s,recur1(i+1,fr));
}
ll recur2(int i,ll c){
if(i==n)return 0;
if(c<v[i].f)return dp2[i][c]=dp1[i][k];
if(dp2[i][c]!=-1)return dp2[i][c];
return dp2[i][c]=max(recur2(i+1,c),recur2(i+1,c-v[i].f)+v[i].s);
}
void solve(int t,int tc){
memset(dp1,-1,sizeof(dp1));
memset(dp2,-1,sizeof(dp2));
cin>>n>>w>>k;
v.resize(n);
for(int i=0;i<n;i++)cin>>v[i].f>>v[i].s;
sort(all(v));
ll ans=0;
for(int i=0;i<n;i++)dp[i][k]=ans=recur1(i,k);
ans=recur2(0,w);
cout<<ans<<e;
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t=1; //cin>>t;
fr(1,t+1)solve(i,t);
return 0;
}