fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std ;
  4.  
  5. int n , a[41] , t[41] ;
  6. long long kq = 0 , sum = 0 , s , p ;
  7.  
  8. void thu( int i )
  9. {
  10. if ( i == n + 1 ) return ;
  11. for ( int j = t[i-1] + 1 ; j <= n ; j ++ ) {
  12. t[i] = j ;
  13. sum += a[j] ;
  14. kq++ ;
  15. if ( sum == s ) {
  16. cout << kq * p << endl ;
  17. exit(0) ;
  18. }
  19. if ( sum < s ) thu ( i + 1 ) ;
  20. sum -= a[j] ;
  21. kq-- ;
  22. t[i] = 0 ;
  23. if ( sum > s ) return ;
  24. }
  25. }
  26.  
  27. int main()
  28. {
  29. cin >> n >> s >> p ;
  30. for ( int i = 1 ; i <= n ; i++ ) cin >> a[i] ;
  31. sort ( 1 + a , 1 + n + a , greater <int> () ) ;
  32. t[0] = 0 ;
  33. thu ( 1 ) ;
  34. cout << -1 ;
  35. }
Success #stdin #stdout 0s 2736KB
stdin
Standard input is empty
stdout
-1