Round #336 A. Saitama Destroys Hotel(Div.2)

Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to s and elevator initially starts on floor s at time 0.

The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.

Input

The first line of input contains two integers n and s (1?≤?n?≤?100, 1?≤?s?≤?1000) — the number of passengers and the number of the top floor respectively.

The next n lines each contain two space-separated integers fi and ti (1?≤?fi?≤?s,1?≤?ti?≤?1000) — the floor and the time of arrival in seconds for the passenger number i.

Output

Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.

Examples

input

3 72 13 85 2

output

11

input

5 102 773 338 219 1210 64

output

79

Note

In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:

1. Move to floor 5: takes 2 seconds.

2. Pick up passenger 3.

3. Move to floor 3: takes 2 seconds.

4. Wait for passenger 2 to arrive: takes 4 seconds.

5. Pick up passenger 2.

6. Go to floor 2: takes 1 second.

7. Pick up passenger 1.

8. Go to floor 0: takes 2 seconds.

This gives a total of 2?+?2?+?4?+?1?+?2?=?11 seconds.

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define MAXN 1005
 4 int a[MAXN];
 5
 6 int main()
 7 {
 8     int n,s;scanf("%d%d",&n,&s);
 9     for(int i=1;i<=n;i++)
10     {
11         int x,t;scanf("%d%d",&x,&t);
12         a[x]=max(t,a[x]);
13     }
14     int x,y;
15     int ans=0;
16     for(int i=s;i>=0;i--)
17     {
18         ans = max(ans,a[i]);
19         ans++;
20     }
21     cout<<ans-1<<endl;
22 }
时间: 2024-10-24 21:23:21

Round #336 A. Saitama Destroys Hotel(Div.2)的相关文章

Codeforces Round #336 (Div. 2) B. Hamming Distance Sum 计算答案贡献+前缀和

B. Hamming Distance Sum Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string s is denoted |s|. The Hamming distance between two strings s and t of equal length is defined as , where si i

Codeforces Round #336 (Div. 2) D. Zuma

D - Zuma 题意:给你一个数字组成的串, 每次你能消去一段连续的回文串,问你最少需要操作几次把所有数字删完. 思路:区间dp, dp[ i ][ j ]表示删 i  到 j 段最少需要几次. 我们只考虑最左边的那个点的删除情况. 首先dp[ i ] [ j ] <= dp[ i + 1] [ j ] + 1 然后我们枚举 i 到 j  里面的点, 找到a[ k ] == a[ i ] 那么可以得到方程 dp[ i ] [ j ] = min (dp[ i ] [ j ] , dp[ i +

Codeforces Round #336 (Div. 2) D. Zuma(区间DP)

题目链接:https://codeforces.com/contest/608/problem/D 题意:给出n个宝石的颜色ci,现在有一个操作,就是子串的颜色是回文串的区间可以通过一次操作消去,问最少需要多少次操作可以消除所有的宝石.(每次操作消除一个回文串,最少操作次数清楚字符串) 题解:dp[l][r]表示区间(l,r)的最少操作次数,对于一个区间(l,r),有两种转移:①若存在c_l = c_i(l <= i <= r),可以由dp[l][i] + dp[i + 1][r]转移:②若c

【Codeforces Round 1129】[Alex Lopashev Thanks-Round] (Div. 1)

Codeforces Round 1129 这场模拟比赛做了\(A1\).\(A2\).\(B\).\(C\),\(Div.1\)排名40. \(A\)题是道贪心,可以考虑每一个站点是分开来的,把目的地最小编号的留到最后,所以答案稍微算一下就行了. \(B\)题是道找规律,首先可以很容易地发现只要前面弄个负数的开头,错误算法就会忽略掉这一个值,所以利用这个来构造答案.(最讨厌构造题了)然后推导一番式子就会发现如果我们将第一个值放-1,则 \(\sum_{i=2}^na_i=k+n\), 再更改一

Round #240 B. Mashmokh and Tokens(Div.2)

Bimokh is Mashmokh's boss. For the following ndays he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens ba

Round #428 A. Arya and Bran(Div.2)

Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by

[Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2) ](A~E)

A: 题目大意:给你一个数字串,每个数字只可以用一次,求最多可以组成多少个电话号码(可以相同),电话号码第一个数字为$8$,且长度为$11$ 题解:限制为$8$的个数和总长度,直接求 卡点:无 C++ Code: #include <cstdio> #include <algorithm> #define maxn 1000 inline int min(int a, int b) {return a < b ? a : b;} inline int max(int a, i

Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2)

A.Phone Numbers 题意:给你n个数字,每个数字最多只能用一次,问你最多能组成以8开头的11位电话号码有多少个 思路:模拟即可,注意char数组读入是从0下标开始的(在这里被hack了...) 1 #include<bits/stdc++.h> 2 int main() 3 { 4 int n,num=0,ans=0; 5 char c[105]; 6 scanf("%d%s",&n,c); 7 for(int i=0;i<n;i++)if(c[i

Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2) C. Maximum Subrectangle

昨天做的,今天才想起来,要写个博客,记一下这种矩阵题怎么做. 首先我没有意识到,每个方向上累和,得到两个累和数组,它们的子序列之积,就是子序列对应的矩形区域范围内所有数字之和,说起来有点抽象,但是举个栗子吧, 就像用例里面的这张提示图,横坐标我选子列2,3,则和为5,纵坐标我选子列1,2,则和为3.那么3和5,乘积为15,而把矩阵中对应区域的和相加,也是15,.则这个问题就容易了:只需要枚举一维数组就可以了.但是,如果枚举一维数组,那岂不是要做一个四重循环?其实不然. 题目要我们获得一个不大于限