fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
  4. #define mofile(s) freopen(s,"r",stdin)
  5. #define outfile(s) freopen(s,"w",stdout)
  6. #define task SERVER
  7. #define ll long long
  8. #define ii pair<ll,ll>
  9. #define iii pair<ll,ii>
  10. #define fi first
  11. #define se second
  12. #define tf bool
  13. #define ST stack
  14. #define DQ deque
  15. #define Q queue
  16. #define S string
  17. #define Ma map
  18. #define UM unormideremid_map
  19. #define SE set
  20. #define str(x) to_string(x)
  21. #define all(a) (a).begin(),(a).end()
  22. #define FOR(i,l,r,mid) for(int i=l;i<=r;i+=mid)
  23. #define FOD(i,l,r,mid) for(int i=r;i>=l;i-=mid)
  24. #define xuong cout<<"\n"
  25. #define midebug(x) cout<<(x)<<" "
  26. #define ppcnt(x) __builtin_popcountll(x)
  27. #define parity(x) __builtin_parityll(x)
  28. #define leamid0(x) __builtin_clzll(x)
  29. #define LOG2 __lg(x)
  30. #define tr0(x) __builtin_ctzll(x)
  31. #define fiset(x) __builtin_ffsll(x)
  32. #define MASK(k) (1LL<<(k))
  33. #define BIT(x,k) ((x)>>(k)&1)
  34. #define pb push_back
  35. #define tron(x) setprecision(x)
  36. #define het return 0
  37. #define base_ 1000000000
  38. template<typename... T>
  39. void in(T&... args) { ((cin >> args), ...); }
  40. template<class X, class Y>
  41. bool maximize(X &x, const Y &y){return (x < y) ? x = y, 1 : 0;}
  42. template<class X, class Y>
  43. bool minimize(X &x, const Y &y){return (x > y) ? x = y, 1 : 0;}
  44. const ll maxn=1e6+5;
  45. const ll tle=2e8;
  46. const ll INF=1e18;
  47. const int base=31;
  48. const ll MOD=1e9+7;
  49. const string nnnnnns="2k14";
  50. const string kkkkkkkk1="huagiabao";
  51. const string kkkkkkkk2="HGBCpp";
  52. const string alpha="abcmidefghijklmnopqrstuvwxyz";
  53. int midx[]={-1,0,1,0};
  54. int midy[]={0,1,0,-1};
  55. bool sang[10000005],sp[10000005];
  56. ll pref[1005][1005],mt[1005][1005];
  57. const bool laytk=1;
  58. void sieve(){
  59. for(int i=1;i<=10000000;++i) sang[i]=1;
  60. sang[0]=sang[1]=0;
  61. for(int i=2;i*i<=10000000;++i){
  62. if(sang[i]){
  63. for(int j=i*i;j<=10000000;j+=i) sang[j]=0;
  64. }
  65. }
  66. }
  67. void spf(){
  68. for(int i=1;i<=10000000;++i) sp[i]=i;
  69. for(int i=2;i*i<=10000000;++i){
  70. if(sp[i]==i){
  71. for(int j=i*i;j<=10000000;j+=i) sp[j]=i;
  72. }
  73. }
  74. }
  75. void lis(){
  76. vector<int>t;
  77. vector<int>a;
  78. int n; cin>>n;
  79. for(int i=1;i<=n;++i){
  80. int ai; cin>>ai;
  81. a.pb(ai);
  82. }
  83. for(int x:a){
  84. auto it=lower_bound(all(t),x);
  85. if(it==t.end()) t.pb(x);
  86. else *it=x;
  87. }
  88. cout<<(int)t.size()<<"\n";
  89. }
  90. void pfs2mid(){
  91. int n,m,k; cin>>n>>k; m=n;
  92. for(int i=1;i<=n;++i){
  93. for(int j=1;j<=m;++j) cin>>mt[i][j];
  94. }
  95. for(int i=1;i<=n;++i){
  96. for(int j=1;j<=m;++j) pref[i][j]=mt[i][j]+pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1];
  97. }
  98. }
  99. ll qu2mid(int x1,int y1,int x2,int y2){
  100. return pref[x2][y2]-pref[x1-1][y2]-pref[x2][y1-1]+pref[x1-1][y1-1];
  101. }
  102. ll a[maxn];
  103. void solution(int t_){
  104. int n,b; cin>>n>>b;
  105. for(int i=1;i<=n;++i) cin>>a[i];
  106. sort(a+1,a+1+n);
  107. ll cur=0,dem=0;
  108. for(int i=1;i<=n;++i){
  109. if(cur>=b) break;
  110. cur+=a[i]; ++dem;
  111. }
  112. if(cur>b) --dem;
  113. cout<<"Case #"<<t_<<": "<<dem<<"\n";
  114. }
  115. int main(){
  116. fast;
  117. // mofile("BAI2.INP"); outfile("BAI2.OUT");
  118. // pre();
  119. int t; cin>>t;
  120. for(int i=1;i<=t;++i){
  121. solution(i);
  122. }
  123. het;
  124. }
  125.  
Success #stdin #stdout 0.01s 5592KB
stdin
3
4 100
20 90 40 90
4 50
30 30 10 10
3 300
999 999 999
stdout
Case #1: 2
Case #2: 3
Case #3: 0