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. 2013-7-31hibernate二级缓存

    难得闲 Fckeditor Fckconfig.js大部分配置都在这里面, 增加字体:         程序代码: FCKConfig.FontNames = 'Arial;Comic Sans MS ...

  2. i8042 键盘控制器-------详细介绍

    [转]http://shanzy.bokee.com/834368.html ps/2 键盘硬件概述 对于驱动来说,和键盘相关的最重要的硬件是两个芯片.一个是 intel 8042 芯片,位于主板上, ...

  3. elasticsearch删除索引报错【原】

    如果elasticsearch删除索引报错 curl -X DELETE 'http://10.73.26.66:9200/httpd-34-2017.08.15' {"error" ...

  4. 码源中国.gitignore忽略文件配置

    码源中国.gitignore忽略文件配置 ## Ignore Visual Studio temporary files, build results, and ## files generated ...

  5. 微信开发,调用js-SDK接口

    微信开发,调用js-SDK接口<!DOCTYPE html><html><head lang="en"> <meta charset=&q ...

  6. [ python ] 练习作业 - 2

    1.写函数,检查获取传入列表或元组对象的所有奇数位索引对应的元素,并将其作为新列表返回给调用者. lic = [0, 1, 2, 3, 4, 5] def func(l): return l[1::2 ...

  7. Bootstrap开发模板

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  8. jquery 修改样式

    //显示待办数字 function showdb(url,ID) {   jQuery.get(url,function(data,status){ if(!isNaN(data)) {  if(da ...

  9. Hadoop(三)HDFS读写原理与shell命令

    一 HDFS概述 1.1 HDFS产生背景 随着数据量越来越大,在一个操作系统管辖的范围内存不下了,那么就分配到更多的操作系统管理的磁盘中,但是不方便管理和维护,迫切需要一种系统来管理多台机器上的文件 ...

  10. log4net 写日志配置

    1. nuget install package log4net 2.站点跟目录新建配置文件 LogWriterConfig.xml <?xml version="1.0" ...