Acdream 1734 Can make a water problem? Greedy

Source: Internet
Author: User

Can you make a water problem?Time limit:2000/1000ms (java/others) Memory limit:128000/64000kb (java/others) Submit statistic Next Problemproblem Descriptionlosanto want to make a water problem. But he has no idea ....
Then he thought a problem:a bus arrived at a station, and there were X persons got off the bus, then y persons got on the Bus. And there were r persons (include the driver) on the bus before the bus in next station. How many is on the bus initially? The driver can ' t get on or off the bus. There is a 1 driver in the bus.
But if the x=8, y=5 r=4, there is something wrong in the problem. After got on 5 persons and there is 4 persons rest ... What a pity! Losanto give x, Y, R want know whether the problem is OK.
Of course few buses have only one station, so there is n stations.
Now give your x and Y for every station, and there are only one person (the driver) rest after the last station. Can you find a suitable order for the station and make the problem OK? Input

There is several cases.

For each case, the first line there is a n, indicate n stations. Then n lines followed, each of which has a numbers XI and Yi. The problem easier, we guarantee that xi>=yi. ( 0<n<100000 0<=xi,yi<1000000) Outputfor each cases, output one, and "Yes" (if you can make a OK order) or "No" (If you can ' t). Sample Input
25 07 425) 23 3
Sample Output
YesNo
MANAGERRIHKDDD Test Instructions: There are n stations, give each station the number of alighted Xi and the number of people Yi, ask how to order the station to meet the objective conditions. Analysis: The station according to the number of passengers from more than a few sorts, and then judged whether the objective conditions, that is, the number of cars should not be less than the number of passengers.
#include <cstdio>#include<iostream>#include<cstring>#include<cmath>#include<stdlib.h>#include<vector>#include<queue>#include<stack>#include<algorithm>#defineLL Long Longusing namespacestd;Const intmaxn=100000+5; LL tot;intN;structnode{intx, y; BOOL operator< (ConstNode A)Const    {        returnx-y>a.x-a.y; }}A[MAXN];BOOLCheak () { for(intI=0; i<n;i++)    {        if(tot<a[i].x)return false; Tot-=a[i].y; }    return true;}intMain () { while(SCANF ("%d", &n)! =EOF) {Tot=0;  for(intI=0; i<n;i++) {scanf ("%d%d",&a[i].x,&a[i].y); Tot+ = (a[i].x-a[i].y); A[i].y= (a[i].x-a[i].y); } sort (A,a+N); Puts (Cheak ()?"Yes":"No"); }    return 0;}
View Code

Acdream 1734 Can make a water problem? Greedy

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.