[2016-03-31] [Codeforces] [659C] [Tanya and Toys]

Source: Internet
Author: User

    • Time: 2016-03-31-23:49:13 Thursday
    • Title Number: [2016-03-31][codeforces][659c][tanya and Toys].md
    • The main topic: There are $10^9$ species of goods, the value of the item I, has used n items, to M-yuan, ask the most can buy the number of items not owned
    • Analysis: Greedy, from the lowest start to buy, assuming $m = 10^9$, then also buy items not more than $10^6$, because $\frac{(1+k) K}{k} < 10^9$
    • Problems encountered: The answer could be 0
  
 
  1. #include <algorithm>
  2. #include <cstdio>
  3. using namespace std;
  4. int a[100000 + 10];
  5. int ans[1000000];
  6. int main(){
  7. int n,m;
  8. scanf("%d%d",&n,&m);
  9. for(int i = 0;i < n ; ++i){
  10. scanf("%d",&a[i]);
  11. }
  12. a[n] = 0;
  13. a[n + 1] = 1E9 + 10;
  14. sort(a,a+n+2);
  15. int = 0 ;
  16. for ( int i = 0 i < n + 2 && m > 0 ++ i ) {
  17. for ( int J = a [ i ] + 1 j < a [ i + 1 ] && Span class= "PLN" > m > 0 ;++ j ) {
  18. m -= j;
  19. if(m < 0) break;
  20. ans[cnt++] = j;
  21. }
  22. }
  23. printf("%d\n",cnt);
  24. for(int i = 0;i < cnt;++i){
  25. printf("%d ",ans[i]);
  26. }
  27. printf("\n");
  28. return 0;
  29. }


From for notes (Wiz)

[2016-03-31] [Codeforces] [659C] [Tanya and Toys]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.