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"); }}