Pagini recente » Cod sursa (job #276571) | Cod sursa (job #2586468) | Cod sursa (job #1283552) | Cod sursa (job #2807795) | Cod sursa (job #1856278)
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#define N 50100
#define INF -1
using namespace std;
struct plasa {
int p , t ;
};
plasa pls [ N ] ;
int fish [ N ] ;
int best [ N ] ;
long long sol [ N ];
bool cmp ( plasa a , plasa b ){
return a.t < b.t ;
}
int main(){
int n , k , tmax , i , j ,id ;
int sum = 0 , temp ;
freopen("peste.in","r",stdin );
freopen("peste.out","w",stdout );
scanf("%d%d%d", &n , &k , &tmax );
for ( i = 0 ; i < n ; i ++ ){
scanf("%d%d",&pls[ i ].p , &pls [ i ].t );
}
sort ( pls , pls + n , cmp );
for ( i = 0 ; i < n ; i ++ ){
j = i ;
fish [ j ] = pls[i].p ;
if ( j < k ){
sum += fish [ j ];
}
while ( j > 0 && fish [ j ] > fish [ j - 1 ] ){
if ( j == k ){
sum = sum + fish [ k ] - fish [ k - 1 ];
}
temp = fish [ j ];
fish [ j ] = fish [ j - 1 ];
fish [ j - 1 ]= temp ;
j-- ;
}
best [ i ] = sum ;
}
for ( i = 0 ; i <= tmax ; i ++ ){
sol [ i ] = INF ;
}
sol [ 0 ] = 0 ;
for ( i = 0 ; i < n ; i ++ ){
for ( j = tmax - pls [ i ] .t ; j >=0 ; j -- ){
if ( sol [ j ] == INF ){
continue ;
}
if ( sol[ j + pls [ i ].t ] < sol [ j ] + best [ i ] ){
sol[ j + pls [ i ].t ] = sol [ j ] + best [ i ] ;
}
for ( id = j + 2 * pls [ i ].t ; id < tmax ; id += pls [ i ].t ){
if ( sol [ id ] < sol [ id - pls[ i ].t ] ){
sol [ id ] = sol [ id - pls[ i ].t ];
}else {
break ;
}
}
}
}
for ( i = 0 ; i <= tmax ; i ++ ){
sol[ tmax ] = max ( sol [ i ] , sol [ tmax ] ) ;
}
if ( sol [ tmax ] == -1 ){
printf("0");
return 0 ;
}
printf("%lld",sol[ tmax ] );
return 0;
}