CSU1584: Train Passengers, csu1584passengers

Source: Internet
Author: User

CSU1584: Train Passengers, csu1584passengers
Description

Input

Output

Sample Input
1 20 1 11 0 0
Sample Output
possible
 
Question: Train capacity c, number of sites n
The number of people on the bus, the number of people on the bus, and the number of waiting persons are provided for each site.
Finally, I asked if I could complete the journey as required.
 
Train of Thought: I have understood this question for a long time, and I will be determined as follows:
1. After the calculation, no one on the bus, no one on the bus, no one waiting
2. exceeding the capacity of the vehicle will inevitably fail
3. If the car is not fully loaded, but there are still waiting persons, then it will not work, because the car is not fully loaded. Why can't I do it? Wait for wool?
 
#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");    }}


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.