Description
Input
Output
Sample Input
1 20 1 11 0 0
Sample Output
Possible
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