fork download
  1. # include <iostream>
  2. # include <fstream>
  3. # include <sstream>
  4. # include <algorithm>
  5. # include <numeric>
  6. # include <cstdio>
  7. # include <cmath>
  8. # include <cstdlib>
  9. # include <cstring>
  10. # include <vector>
  11. # include <list>
  12. # include <set>
  13. # include <map>
  14. # include <stack>
  15. # include <queue>
  16. # include <cctype>
  17. # include <climits>
  18. # include <complex>
  19.  
  20. using namespace std;
  21.  
  22. typedef long long LL;
  23. typedef unsigned long long ULL;
  24. typedef pair<int,int> pii;
  25. typedef vector<int> vi;
  26. typedef vector<vector<int> > vvi;
  27.  
  28. #define GI ({int t;scanf("%d",&t);t;})
  29. #define REP(i,a,b) for(int i=a;i<b;i++)
  30. #define ALL(v) (v).begin(),(v).end()
  31. #define TR(i,x) for(typeof(x.begin()) i=x.begin();i!=x.end();i++)
  32. #define pb push_back
  33. #define mp make_pair
  34. #define INF (int)1e9
  35. #define EPS (double)(1e-9)
  36. #define PI (double)(3.141592653589793)
  37.  
  38. int main()
  39. {
  40. int n,m,k,a[55],sum=0,direct,indirect;
  41. cin>>n>>m>>k;
  42. REP(i,0,n) a[i]=GI;
  43. if(k>=m)
  44. {printf("0\n");return 0;}
  45. sort(a,a+n,greater<int>());
  46. REP(i,0,k)
  47. {
  48. sum+=a[i];
  49. if(sum+(k-i-1)>=m)
  50. {printf("%d\n",i+1);return 0;}
  51. }
  52. REP(i,k,min(k+sum,n))
  53. {
  54. sum+=(a[i]-1);
  55. if(sum>=m)
  56. {printf("%d\n",i+1); return 0;}
  57. }
  58. printf("-1\n");
  59. return 0;
  60. }
  61.  
  62.  
Success #stdin #stdout 0.02s 2684KB
stdin
5 50 6
2 1 3 1 3
stdout
-1