Csu1584:train passengers

Source: Internet
Author: User




Sample Input
1 20 1 11 0 0
Sample Output
Test instructions: Give train capacity C, number of sites n
For each site give the number of passengers, get off the number and waiting for the number
Ask if you can finish the journey on request
Idea: This problem has been understood for quite a long time, and was later determined as follows
1. The last stop, after the calculation, must be no one in the car, nobody on the bus, no one waiting
2. Beyond the capacity of the vehicle, must not
3. If the car is not full, but there are waiting for the person, then it is not possible, because the car is not full I why not on Ah, still waiting for the yarn
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue > #include <map> #include <set> #include <vector> #include <math.h> #include <algorithm >using namespace std, #define LS 2*i#define rs 2*i+1#define up (i,x,y) for (i=x;i<=y;i++) #define DOWN (i,x,y) for (i=x; i>=y;i--) #define MEM (a,x) memset (A,x,sizeof (a)) #define W (a) while (a) #define LL long longconst double pi = acos (-1.0); #    Define Len 200005#define mod 360000const int INF = 0x3f3f3f3f; #define EXP 1e-6int Main () {LL c,n,sum,w,a,b,c;        W (scanf ("%lld%lld", &c,&n) >0) {sum=0;        w=0;        int flag=0;            W (n--) {scanf ("%lld%lld%lld", &a,&b,&c);            if (flag) continue;                if (sum<a) {flag=1;            Continue            } sum=sum-a+b;            if (sum>c) flag=1; if (sum!=c && C)flag = 1;        if (!n && (sum | | b | | c)) flag = 1;        } if (flag) printf ("impossible\n");    else printf ("possible\n"); }}

Csu1584:train passengers

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.