#include <iostream>
using namespace std;
int
n, m, t, cost[1002], f[1002], g[1002];
void
__read__()
{
cin >> n >> m >> t;
for( int i = 1; i <= n; i++ )
cin >> cost[i];
}
void
__init__() //这个init有点不好理解
{
f[0] = 0;
g[0] = 9999999;
for( int i = 1; i <= n; i++ )
f[i] = 9999999;
}
void
__dp__()
{
for( int i = 1; i <= n; i++ )
for( int j = i; j > 0; j-- )
if( g[j - 1] + cost[i] > t )
{
if( f[j - 1] + 1 < f[j] )
{
f[j] = f[j - 1] + 1;
g[j] = cost[i];
}
if( f[j - 1] + 1 == f[j] )
if( g[j] > cost[i] )
g[j] = cost[i];
}
else
{
if( f[j - 1] < f[j] )
{
f[j] = f[j - 1];
g[j] = g[j - 1] + cost[i];
}
if( f[j - 1] == f[j] )
if( g[j] > g[j - 1] + cost[i] )
g[j] = g[j - 1] + cost[i];
}
}
void
__outp__()
{
for( int i = n; i > 0; i-- )
if( f[i] <= m )
{
cout << i << endl;
return;
}
}
int
main()
{
__read__();
__init__();
__dp__();
__outp__();
return 0;
}