C. Tourist's Notes

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/538/problem/C

Description

A tourist hiked along the mountain range. The hike lasted for n days, during each day the tourist noted height above the sea level. On the i-th day height was equal to some integer hi. The tourist pick smooth enough route for his hike, meaning that the between any two consecutive days height changes by at most 1, i.e. for all i's from 1 to n - 1 the inequality |hi - hi + 1| ≤ 1 holds.

At the end of the route the tourist rafted down a mountain river and some notes in the journal were washed away. Moreover, the numbers in the notes could have been distorted. Now the tourist wonders what could be the maximum height during his hike. Help him restore the maximum possible value of the maximum height throughout the hike or determine that the notes were so much distorted that they do not represent any possible height values that meet limits |hi - hi + 1| ≤ 1.

Input

The first line contains two space-separated numbers, n and m (1 ≤ n ≤ 108, 1 ≤ m ≤ 105) — the number of days of the hike and the number of notes left in the journal.

Next m lines contain two space-separated integers di and hdi (1 ≤ di ≤ n, 0 ≤ hdi ≤ 108) — the number of the day when the i-th note was made and height on the di-th day. It is guaranteed that the notes are given in the chronological order, i.e. for all i from 1 to m - 1 the following condition holds: di < di + 1.

Output

If the notes aren't contradictory, print a single integer — the maximum possible height value throughout the whole route.

If the notes do not correspond to any set of heights, print a single word 'IMPOSSIBLE' (without the quotes).

Sample Input

8 2
2 0
7 0

Sample Output

2

HINT

题意

给你n天,我们知道m天爬到了k米高,然后每天最多爬1m或者掉下来1m,然后问你最高的可能性高度是多高

题解:

数学问题……

直接想公式就好

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** struct node
{
ll x,y;
};
bool cmp(node a,node b)
{
return a.x<b.x;
}
node a[maxn];
int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<m;i++)
cin>>a[i].x>>a[i].y;
sort(a,a+m,cmp);
ll ans=max(a[].x+a[].y-,n-a[m-].x+a[m-].y);
// cout<<ans<<endl;
for(int i=;i<m-;i++)
{
if(abs(a[i].y-a[i+].y)>abs(a[i].x-a[i+].x))
{
printf("IMPOSSIBLE");
return ;
}
int dota=abs(a[i].x-a[i+].x)-abs(a[i].y-a[i+].y);
ans=max(ans,max(a[i].y,a[i+].y)+dota/); }
cout<<ans<<endl;
}

Codeforces Round #300 C. Tourist's Notes 水题的更多相关文章

  1. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  2. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  3. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  4. Codeforces Round #190 (Div. 2) 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

  5. Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

    对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...

  6. Educational Codeforces Round 12 A. Buses Between Cities 水题

    A. Buses Between Cities 题目连接: http://www.codeforces.com/contest/665/problem/A Description Buses run ...

  7. Codeforces Round #377 (Div. 2) C. Sanatorium 水题

    C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  9. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

随机推荐

  1. AUC画图与计算

    利用sklearn画AUC曲线 from sklearn.metrics import roc_curve labels=[1,1,0,0,1] preds=[0.8,0.7,0.3,0.6,0.5] ...

  2. 【Tomcat】tomcat中server.xml配置详解

    Tomcat Server的结构图如下: 该文件描述了如何启动Tomcat Server <Server>    <Listener />    <GlobaNaming ...

  3. python并发编程之threading线程(一)

    进程是系统进行资源分配最小单元,线程是进程的一个实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位.进程在执行过程中拥有独立的内存单元,而多个线程共享内存等资源. 系列文章 py ...

  4. flask插件系列之flask_cors跨域请求

    前后端分离在开发调试阶段本地的flask测试服务器需要允许跨域访问,简单解决办法有二: 使用flask_cors包 安装 pip install flask_cors 初始化的时候加载配置,这样就可以 ...

  5. OTA之流式更新及shell实现

    在OTA升级时,需要从网络下载OTA包,并写到flash上的对应分区中. 最简单的方式是将下载与更新分离,先将完整的数据包下载到本地,再将本地的OTA包更新到flash上.方便可靠. 但这种方式的问题 ...

  6. shell中的变量与eval(转)

    原文链接:http://www.361way.com/shell-eval-variable/4957.html shell 中经常会用到变量的嵌套的情况.比如,单个或多个变量的值作为变量名,再对该变 ...

  7. C# 获取计算机cpu,硬盘,内存相关的信息

    using System;using System.Management; namespace MmPS.Common.Helper{ /// <summary> /// 获取计算机相关的 ...

  8. v4l

    v4l 2011-11-08 11:01:54|  分类: 默认分类|举报|字号 订阅     第一个部分介绍一些v4l的基本概念和基本方法,利用系统API完成一系列函数以方便后续应用程序的开发和使用 ...

  9. MVC开发模式与javaEE三层架构

    1.MVC开发模式 1. M:Model,模型.JavaBean        * 完成具体的业务操作,如:查询数据库,封装对象2. V:View,视图.JSP        * 展示数据3. C:C ...

  10. js自动检索输入文章长度

    1. 代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...