1715 soldiers of the Acdream kingdom

Source: Internet
Author: User

problem Description

The so-called weak country does not have diplomacy, the Acdream kingdom wants to hold this piece of land, naturally cannot leave the kingdom's soldiers, you as the kingdom's King general, naturally has the duty which trains the Kingdom soldier. The kingdom has n soldiers, each soldier has two attributes, attacks and defenses. Then you want to go through a series of adjustments, each soldier can become a qualified soldier, so-called qualified soldiers, refers to his attack and defense of greater than or equal to K. Your adjustment is to swap the same attribute of two soldiers, that is, swapping two soldiers for an attack, or defending the exchange, or exchanging attacks and defenses (though this is meaningless). There is no limit to the number of adjustments you have. Can you make all the soldiers a qualified soldier, please?

Input

Multiple sets of data, each set of data is first two integers n (1<=n<=1000), K (1<=k<=10^9) Next is a line of integers, a total of N, representing the attack value of N soldiers
Next is a line of integers, a total of N, representing the defensive values of N soldiers.

Output

For each set of data, if you can pass the limited exchange, so that all soldiers are qualified soldiers, the output "YES", otherwise output "no" (do not need double quotes, note case)

Code
#include <cstdio>#include <algorithm>using namespace STD;intMain () {intNLong LongK, a[1005], b[1005]; while(scanf("%d%lld", &n, &k)! = EOF) { for(inti =0; I < n; i++)scanf("%lld", &a[i]); for(inti =0; I < n; i++)scanf("%lld", &b[i]);        Sort (A, a + N); Sort (b, B + N);BOOLOK =true; for(inti =0; I < n && OK; i++)if(A[i] + b[n-i-1] < K) OK =false;printf("%s\n"Ok?"YES":"NO"); }return 0;}

1715 soldiers of the Acdream kingdom

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.