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. MYSQL源代码编译的变动

    Mysql的安装,对于mysql不同版本号的mysql源代码编译方式不一样 5.6.2的版本号開始编译方式已经由 configure 变成了cmake方式 ,相关的新的 编译方式在mysql官网已经提 ...

  2. [javase学习笔记]-8.8 构造代码块

    这一节我们再看一个特殊的代码块.那就是构造代码块. 这里我们简单的通过样例来说明一下: class Person { private String name; { System.out.println ...

  3. Thinkphp 无法使用-&gt;order() 排序的两种解决的方法!

    使用ThinkPHP,却发现无法使用->order($order)来排序. $order = " info.date2 desc "; 非常遗憾的是这样写结果order却变成 ...

  4. CG 内置函数 和 HLSL 内置函数

    CG 内置函数  英伟达官网链接: http://http.developer.nvidia.com/Cg/index_stdlib.html absacosallanyasinatan2atanbi ...

  5. BZOJ 球形空间产生器 解题报告(高斯消元)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1013 1013: [JSOI2008]球形空间产生器sphere 有一个球形空间产生器能 ...

  6. 互不侵犯_状压$dp$

    如果有想学习状压\(dp\)的童鞋,请光临博客状压\(dp\)初学 互不侵犯 题目描述 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八 ...

  7. 函数式JS: 原来promise是这样的monad

    转载请注明出处: http://hai.li/2017/03/27/prom... 背景 上篇文章 函数式JS: 一种continuation monad推导 得到了一个类似promise的链式调用, ...

  8. twig 模板引擎使渲染视图更加优雅

    在使用 laravel 的时候接触过 blade 模板引擎.在学习的时候,接触到了另外一个强大的模板引擎:twig 官网:https://twig.sensiolabs.org/ 中文手册:http: ...

  9. session 存入 redis

    <?php header('content-type:text/html;charset=utf-8'); /* * 更改 session 存储位置及存储方式. */ ini_set('sess ...

  10. Kubernetes1.5 集成dashboard

    Kubernetes1.5 集成dashboard 配置kubernetes的dashboard相对简单.同样的,只需要从源码中获取到dashboard-controller.yaml及dashboa ...