[ACM] blockchain Distribution

Source: Internet
Author: User

Time limit:1000 msMemory limit:65535kb
Total submissions:539Accepted:52

Description:

The singer pancakes went to kindergarten to play with the children. When she arrived, the children were fighting for building blocks. The children wanted more blocks to build their favorite graphics. After the building, they could take photos with pancakes.
At the same time, Pancakes has some building blocks on her hands. She can give all the building blocks to a child. Then, after the child finishes building the blocks, she can take back the blocks and the blocks on the child's hand.
But she doesn't know if she can let all the children take photos with her. Can you help her intelligently?

Input:

The input contains multiple data.
The first row of each data is two positive integers N and S. The range of N is [1st], and the range of S is [], indicating a total of N children, pancakes has s blocks. There are n rows below. Each row has two positive integers, A and B. The range of A and B is [^ 9], indicating that the first child has a block, B blocks are required to complete the building.
Input n = 0 indicates the end.

Output:

If you want all the children to take a photo, "yes" is output; otherwise, "no" is output ".

Sample input:

2 2
1 4
2 1
2 2
1 4
1 1
0 0

Sample output:

Yes
No

Hint:

 

Source:

Gdcpc

 

Answer:

This question is relatively simple. You only need to give a child the number of building blocks less than the number of building blocks in the artist's hand, and then the number of building blocks can be recovered, and get the building blocks in the children's hands. This question does not need to be greedy; otherwise, timeout may occur.CodeAs follows:

 

<! --

Code highlighting produced by actipro codehighlighter (freeware)
Http://www.CodeHighlighter.com/

--># Include<Stdio. h>
# Include<Vector>
# Include<Algorithm>

Using NamespaceSTD;

struct child
{< br> int own;
int less;
};

IntChild_cmp (ConstChild&A,ConstChild&B)
{
ReturnA. Less<B. Less;
}

Int Main ()
{
Int N, S, I, can;
Vector < Child > : Iterator it;
While ( 1 )
{
Scanf ( " % D " , & N, & S );
If (N =   0 )
Break ;

Vector < Child > CLS;
For (I =   0 ; I < N; I ++ )
{
Child X;
Scanf ( " % D " , & X. Own, & X. Less );
Cls. push_back (X );
}
Can =   True ;
Make_heap (CLS. Begin (), CLS. End (), child_cmp );
Sort_heap (CLS. Begin (), CLS. End (), child_cmp );
For (It = Cls. Begin (); it ! = Cls. End (); it ++ )
{
If (It -> Less <= S)
S + = It -> Own;
Else
{
Can =   False ;
Break ;
}
}
If (CAN)
Printf ( " Yes
" );
Else
Printf ( " No
" );
}
Return   0 ;
}

 

Struct is used in the code, which may affect the speed. You can change it to two arrays to increase the speed. SortAlgorithmSystem Heap sorting is also used.

Related Article

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.