Train Passengers

Time Limit: 1000ms
Memory Limit: 524288KB

This problem will be judged on CodeForcesGym. Original ID: 100502K
64-bit integer IO format: %I64d      Java class name: (Any)

  The Nordic Company of Passing Carriages is losing money at an alarming rate because most of their trains are empty. However, on some lines the passengers are complaining that they cannot fit in the cars and have to wait for the next train! The authorities want to fix this situation. They asked their station masters to write down, for a given train, how many people left the train at their station, how many went in, and how 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 you remembered that they were collected on a snowy day, so any sensible station master would have preferred to stay inside their cabin and make up the numbers instead of going outside and counting. Verify your hunch by checking whether the input is inconsistent, i.e., at every time the number of people in the train did not exceed the capacity nor was below 0 and no passenger waited in vain. The train should start and finish the journey empty, in particular passengers should not wait for the train at the last station.

Input

The first line contains two integers C and n (2 ≤ n ≤ 100), the total capacity and the number of stations the train stops in. The next n lines contain three integers each, the number of people that left the train, entered the train, and had to stay at a station. Lines are given in the same order as the train visits each station. All integers including C are between 0 and 109 inclusive.

Output

One line containing one word: possible if the measurements are 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

解题:直接模拟就好

 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
bool check(int n,int C){
int left,went,wait;
LL cur = ;
bool flag = true;
for(int i = ; i < n; ++i){
scanf("%d %d %d",&left,&went,&wait);
if(cur - left < ) flag = false;
cur += went - left;
if(cur > C || cur < C && wait) flag = false;
}
if(cur != ) flag = false;
return flag;
}
int main(){
int n,C;
while(~scanf("%d %d",&C,&n))
printf("%spossible\n",check(n,C)?"":"im");
return ;
}

CodeForcesGym 100502K Train Passengers的更多相关文章

  1. 判断 Gym 100502K Train Passengers

    题目传送门 /* 题意:几个判断,车上的人不能 <0 或 > C:车上初始和结束都不能有人在 (为0):车上满员时才有等候的人 水题:难点在于读懂题目意思,状态不佳,一直没搞懂意思,在这题 ...

  2. 【模拟】NCPC 2014 K Train passengers

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1797 题目大意: 有N个车站,火车一共可以坐M个人,每个车站下车Ai,上车Bi个人,在 ...

  3. 2017ICPC南宁赛区网络赛 Train Seats Reservation (简单思维)

    You are given a list of train stations, say from the station 111 to the station 100100100. The passe ...

  4. B. Train Seats Reservation 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛

    You are given a list of train stations, say from the station 1 to the station 100. The passengers ca ...

  5. 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Train Seats Reservation

    You are given a list of train stations, say from the station 11 to the station 100100. The passenger ...

  6. CodeForcesGym 100676G Training Camp

    G. Training Camp Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...

  7. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  8. 清华学堂 列车调度(Train)

    列车调度(Train) Description Figure 1 shows the structure of a station for train dispatching. Figure 1 In ...

  9. Organize Your Train part II-POJ3007模拟

    Organize Your Train part II Time Limit: 1000MS Memory Limit: 65536K Description RJ Freight, a Japane ...

随机推荐

  1. Linux下安装过程中编译PHP时报错:configure: error: libjpeg.(a|so) not found

    在Linux下安装PHP过程中,编译时出现configure: error: libjpeg.(a|so) not found 错误的解决的方法: 检查之后发现已经安装libjpeg.可是/usr/l ...

  2. pandas dataframe 做机器学习训练数据=》直接使用iloc或者as_matrix即可

    样本示意,为kdd99数据源: 0,udp,private,SF,105,146,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0.00,0.00,0.00,0.00,1.0 ...

  3. 15.map映射

    #include <iostream> #include <map> #include <cstring> using namespace std; //map常规 ...

  4. POJ 1151 线段树+扫描线

    题意:求矩形面积的并 思路: 注意是[l,mid][mid,r] 这是真正的线段了 就当扫描线模板使吧~ //By SiriusRen #include <cmath> #include ...

  5. h5调用手机前后摄像头,拍照

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="pacam.aspx.cs& ...

  6. 使用greenDAO遇到的问题

    前一阵花时间学习了一下greenDAO的使用,这两天已经把项目中之前使用的sqlite数据库操作改用greenDAO,但是在改动的过程中还是出了一些问题,问题主要集中在主键上,下面整理了一下在改动过程 ...

  7. 滑动切换Activity代码

    最近需要对练习项目中的代码进行优化,发现很多代码写起来远比想象的困难很多.刚接触Android时间不长,很多东西都不能融会贯通,所以才会有这样的问题存在,当然学习中遇到的问题很有必要做个总结.想想这个 ...

  8. OpenGL编程(五)绘直线以及分析绘直线的算法

    这次主要实现在窗口上绘制点.线以及修改其属性,另外还会分析画直线的原理和相关算法. 1.在窗口指定位置画点 glBegin(GL_POINTS); glEnd(); 使用glBegin()和glEnd ...

  9. SQLServer中同义词Synonym的用法

    以前一直认为SqlServer中的同义词(Synonym)没有什么用处,所以也一直没有去查它的语法格式.今天碰到一个问题,用Synonym来解决再好不过了.问题是这样子的,我的系统中用到了多个数据库, ...

  10. 使用python抓取App数据

    App接口爬取数据过程使用抓包工具手机使用代理,app所有请求通过抓包工具获得接口,分析接口反编译apk获取key突破反爬限制需要的工具:夜神模拟器FiddlerPycharm实现过程首先下载夜神模拟 ...