Advertisement
TimxAG

Untitled

Sep 10th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int a[1000010];
  4. int main()
  5. {
  6. int n,p,i,q,k,minn=1000000,maxx=0,uk=0,count=0,count1=0,t;
  7. scanf("%d%d",&n,&p);
  8. for(i=1; i<=n; i++)
  9. {
  10. scanf("%d",&q);
  11. a[q]++;
  12. minn=min(minn,q);
  13. maxx=max(maxx,q);
  14. }
  15. for(i=minn; i<=maxx; i++)
  16. if(a[i]!=0)
  17. {
  18. if(a[i]*i>p) break;
  19. count1+=a[i];
  20. count++;
  21. }
  22. for(k=minn; k<i; k++)
  23. if(a[k]!=0)
  24. {
  25. for(t=k+1; t<i; t++)
  26. if(a[t]!=0) break;
  27. if(a[t]==0) break;
  28. if(t*(a[k]+a[t])<=p)
  29. {
  30. count--;
  31. a[t]+=a[k];
  32. a[k]=0;
  33. }
  34. }
  35. printf("%d %d\n",count1,count);
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement