# Codeforcesgym 100502K Train Passengers

Source: Internet
Author: User

Train passengerstime limit:1000msmemory limit:524288kbthis problem would be judged onCodeforcesgym. Original id:100502k
64-bit integer IO format: %i64d Java class name: (any)

The Nordic company of passing carriages was losing money at a alarming rate because most of their trains was empty. However, on some lines the passengers is complaining that they cannot? t in the cars and has to wait for the next train! The authorities want to? x this situation. They asked their station masters to write off, for a given train, how many people left the train at their station, how Ma NY went in, and what many had to wait. Then they hired your company of highly paid consultants to assign properly sized trains to their routes.

You just received the measurements for a train,but before feeding them to your optimisation algorithm your remembered that They were collected on a snowy day, so any sensible station master would has preferred to stay inside their cabin and MAK e up the numbers instead of going outside and counting. Verify your hunch by checking whether the input was inconsistent, i.e., at every time the number of people in the train did not exceed the capacity nor is below 0 and no passenger waited in vain. The train should start and Nish the journey empty, in particular passengers should not wait for the train at the last STA tion.

Input

The. RST line contains II integers C and N (2≤n≤100), the total capacity and the number of stations the train stops I N. The next n lines contain three integers each, the number of the people so left the train, entered the train, and had to s Tay at a station. Lines is given in the same order as the train visits each station. All integers including C is between 0 and 109 inclusive.

Output

One line containing one word:possible if the measurements is consistent, impossible otherwise.

Sample Input 1

1 2

0 1 1

1 0 0

Sample Output 1

Possible

Sample Input 2

1 2

1 0 0

0 1 0

Sample Output 2

Impossible

Sample Input 3

1 2

0 1 0

1 0 1

Sample Output 3

Impossible

Sample Input 4

1 2

0 1 1

0 0 0

Sample Output 4

Impossible

Problem solving: Direct simulation is good

```

1 #include <bits/stdc++.h>
2 using namespace std;
3 typedef long long LL;
4 bool check(int n,int C){
5     int left,went,wait;
6     LL cur = 0;
7     bool flag = true;
8     for(int i = 0; i < n; ++i){
9         scanf("%d %d %d",&left,&went,&wait);
10         if(cur - left < 0) flag = false;
11         cur += went - left;
12         if(cur > C || cur < C && wait) flag = false;
13     }
14     if(cur != 0) flag = false;
15     return flag;
16 }
17 int main(){
18     int n,C;
19     while(~scanf("%d %d",&C,&n))
20         printf("%spossible\n",check(n,C)?"":"im");
21     return 0;
22 }

```

Codeforcesgym 100502K Train Passengers

Related Keywords:

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.