1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include <bits/stdc++.h> using namespace std;
const int maxn = 2e5 + 50; int l, s, t, m; int a[105], stone[maxn], f[maxn];
int main( ) { cin >> l >> s >> t >> m; for( int i = 1; i <= m; ++ i ) cin >> a[i];
if( s == t ) { int cnt = 0; for( int i = 1; i <= m; ++ i ) if( a[i] % s == 0 ) ++ cnt; cout << cnt << "\n"; return 0; }
sort( a + 1, a + m + 1 ); a[0] = 0; int current_len = 0; const int gap = 100;
for( int i = 1; i <= m; ++ i ) { int d = a[i] - a[i - 1]; current_len += min( d, gap ); stone[ current_len ] = 1; } l = current_len + min( l - a[ m ], gap );
memset( f, 0x3f, sizeof( f ) ); f[ 0 ] = 0;
for( int i = 1; i <= l + t; ++ i ) { for( int j = s; j <= t; ++ j ) { if( i >= j ) f[i] = min( f[i], f[i - j] + stone[i] ); } }
int ans = 105; for( int i = l; i <= l + t; ++ i ) ans = min( ans, f[i] ); cout << ans << "\n";
return 0; }
|