D1. Toy Train (Simplified)
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

This is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled.

Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of nn stations, enumerated from 11through nn. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit after station ii is station i+1i+1 if 1≤i<n1≤i<n or station 11 if i=ni=n. It takes the train 11 second to travel to its next station as described.

Bob gave Alice a fun task before he left: to deliver mm candies that are initially at some stations to their independent destinations using the train. The candies are enumerated from 11 through mm. Candy ii (1≤i≤m1≤i≤m), now at station aiai, should be delivered to station bibi (ai≠biai≠bi).

The blue numbers on the candies correspond to bibi values. The image corresponds to the 11-st example.

The train has infinite capacity, and it is possible to load off any number of candies at a station. However, only at most one candy can be loaded from a station onto the train before it leaves the station. You can choose any candy at this station. The time it takes to move the candies is negligible.

Now, Alice wonders how much time is needed for the train to deliver all candies. Your task is to find, for each station, the minimum time the train would need to deliver all the candies were it to start from there.

Input

The first line contains two space-separated integers nn and mm (2≤n≤1002≤n≤100; 1≤m≤2001≤m≤200) — the number of stations and the number of candies, respectively.

The ii-th of the following mm lines contains two space-separated integers aiai and bibi (1≤ai,bi≤n1≤ai,bi≤n; ai≠biai≠bi) — the station that initially contains candy ii and the destination station of the candy, respectively.

Output

In the first and only line, print nn space-separated integers, the ii-th of which is the minimum time, in seconds, the train would need to deliver all the candies were it to start from station ii.

Examples
input

Copy
  1. 5 7
  2. 2 4
  3. 5 1
  4. 2 3
  5. 3 4
  6. 4 1
  7. 5 3
  8. 3 5
output

Copy
  1. 10 9 10 10 9
input

Copy
  1. 2 3
  2. 1 2
  3. 1 2
  4. 1 2
output

Copy
  1. 5 6
Note

Consider the second sample.

If the train started at station 11, the optimal strategy is as follows.

  1. Load the first candy onto the train.
  2. Proceed to station 22. This step takes 11 second.
  3. Deliver the first candy.
  4. Proceed to station 11. This step takes 11 second.
  5. Load the second candy onto the train.
  6. Proceed to station 22. This step takes 11 second.
  7. Deliver the second candy.
  8. Proceed to station 11. This step takes 11 second.
  9. Load the third candy onto the train.
  10. Proceed to station 22. This step takes 11 second.
  11. Deliver the third candy.

Hence, the train needs 55 seconds to complete the tasks.

If the train were to start at station 22, however, it would need to move to station 11 before it could load the first candy, which would take one additional second. Thus, the answer in this scenario is 5+1=65+1=6 seconds.

D1. Toy Train (Simplified)的更多相关文章

  1. Codeforces Round #542(Div. 2) D1.Toy Train

    链接:https://codeforces.com/contest/1130/problem/D1 题意: 给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果. 求从 ...

  2. Codeforces 1130D1 Toy Train (Simplified) (思维)【贪心】

    <题目链接> 题目大意: 有一个的环形火车站,其中有$[1,n] n$个站台,站台上能够放糖果,火车只能朝一个方向移动,如果火车在站台$i$,那么下一秒就会在$i+1$站(如果$i=n$, ...

  3. CF1130D Toy Train

    D Toy Train 开始时,对于一个点 \(x\) ,若没有糖果需要运走,则不考虑; 否则,若点上有 \(k\) 颗糖果需要运走,火车每次只能搭上 \(1\) 个,显然经过这个点至少 \(k\) ...

  4. D2. Toy Train

    D2. Toy Train time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. Toy Train(贪心)

    题目链接:http://codeforces.com/contest/1130/problem/D1 题目大意:给你n个点,然后m条运输任务,然后问你从每个点作为起点是,完成这些运输任务的最小花费?每 ...

  6. DMOJ IOI '17 P3 - Toy Train【拓扑排序】

    传送:https://dmoj.ca/problem/ioi17p3 参考:https://blog.csdn.net/qq_27327327/article/details/80711824 妙啊- ...

  7. 【Codeforces 1129A】Toy Train

    [链接] 我是链接,点我呀:) [题意] 火车从1,2,3...n->1的方式绕圈走.(即每次从i走到i+1) 有一些点有货物需要装载,但是每个点只能装上去一个货物. 每个货物都有目标点卸货点( ...

  8. Codeforces-542div2

    https://www.cnblogs.com/31415926535x/p/10468017.html codeforces-1130A~G 和队友做了一套题,, A. Be Positive 题意 ...

  9. CF 1130A 1130B 1130C1129A1 1129A2 1129B(Round542A B C D1 D2 E)题解

    A : Be Positive 题目地址:https://codeforces.com/problemset/problem/1130/A 题解:让你求是否满足一个d使得数列长为n的a数组的每个数除以 ...

随机推荐

  1. 【转】Android性能优化-过度绘制解决方案

    转载请注明出处:http://blog.csdn.net/a740169405/article/details/53896497 过度绘制: 屏幕上某一像素点在一帧中被重复绘制多次,就是过度绘制. 下 ...

  2. ES6 基础知识-----简记 let const

    ES5中只有函数作用域和全局作用域,声明变量使用var,在es6中添加声明变量 let const let 声明块级作用域变量, let 不存在变量提升 var命令会发生”变量提升“现象,即变量可以在 ...

  3. HDU 3944 DP? (Lucas定理)

    题意:在杨辉三角中让你从最上面到 第 n 行,第 m 列所经过的元素之和最小,只能斜向下或者直向下走. 析:很容易知道,如果 m 在n的左半部分,那么就先从 (n, m)向左,再直着向上,如果是在右半 ...

  4. 金融事业部QA培训体系

    此文已由作者夏君授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 引言     总结2015,放眼2016,纵观整个互联网圈,人才依然是业务成功的第一要素,在网易,我想也是这样 ...

  5. Excel学习 -- 数据透视表功能

    Excel -- 数据透视表基础 数据透视表(Pivot Table)是一种交互式的表,可以进行某些计算,如求和与计数等.所进行的计算与数据跟数据透视表中的排列有关.    之所以称为数据透视表,是因 ...

  6. Math对象常用方法(取整细节)

    Math 对象 Math 对象用于执行数学任务. 1.常用属性: 1.E :返回算术常量e,即自然对数的底数(约2.718) 2.PI :返回圆周率,约3.14159 2.常用方法    Math.方 ...

  7. 洛谷 P4009 汽车加油行驶问题 【最小费用最大流】

    分层图,建k层,设(i,j,0)为点(i,j)的满油状态,全图的流量都是1,因为重复走到一个点没有意义.如果当前点是加油站,那么它向它上左的点连费用为a的边,向下右连费用为a+b的边: 否则,这个点的 ...

  8. Element-wise operations

    Element-wise operations An element-wise operation operates on corresponding elements between tensors ...

  9. Lodash 方法库 原生实现 待完结。。。

    'use strict' let _ = { // 将数组(array)拆分成多个 size 长度的区块,并将这些区块组成一个新数组. 如果array 无法被分割成全部等长的区块,那么最后剩余的元素将 ...

  10. 洛谷P2384 最短路(dijkstra解法)

    题目背景 狗哥做烂了最短路,突然机智的考了Bosh一道,没想到把Bosh考住了...你能帮Bosh解决吗? 他会给你100000000000000000000000000000000000%10金币w ...