M - Notifications

SDUT 2022 Spring Individual Contest(for 21) - 6 - Virtual Judge

Vasya is sitting at a computer. Sometimes he receives notifications about new videos on his favourite Youtube channel. Then,

  • if he isn't watching any video at the moment, he clicks the notification and starts to watch this video till the end,
  • if he is already watching a video at the moment, he will firstly watch all unfinished videos (about which he received notification earlier), and then click the new notification and watch the new video till the end.

You are given nn parameters of the notifications: the ii-th notification is received at the moment of time t_iti​ and contains the video of length d_idi​. Find when Vasya will stop watching the last video.

Input

The first line contains the integer nn (1 \le n \le 2000001≤n≤200000) — the number of notifications.

Each of the next nn lines contains two integers t_iti​ and d_idi​ (1 \le t_i, d_i \le 10^91≤ti​,di​≤109) — the moment of time when Vasya receives the ii-th notification, and the length of the video in this notification.

All t_iti​ form non-decreasing sequence, i. e. t_i \le t_{i+1}ti​≤ti+1​ for all ii from 1 to (n-1)(n−1).

Output

Output one integer — the moment of time when Vasya will stop watching the last video.

Sample 1

InputcopyOutputcopy
5
1 4
3 3
6 1
10 2
10 3
15

Note

In the given example the sequence of Vasya's actions is the following:

1) At the moment 1 he receives a notification about the video of length 4. As he isn't watching any video at the moment, he starts to watch it till the moment of time 5.

2) At the moment 3 he receives a notification about the video of length 3, but he is watching the first video at the moment, so he will start watching this video at the moment 5 (just after the first one) and finish at the moment 8.

3) At the moment 6 he receives a notification about the video of length 1. He will watch it from the moment 8 to the moment 9.

4) From the moment 9 to the moment 10, Vasya is not doing anything.

5) At the moment 10 he receives two notification — about the videos of lengths 2 and 3. He will watch them in the order he receives them, so he will watch the first of them from 10 to 12, and the other one — from 12 to 15.

 

#include<bits/stdc++.h>
using namespace std;
struct Node
{
    long long a,b;
}node[200005];
bool cmp(Node x,Node y)
{
    return x.a<y.a;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%lld %lld",&node[i].a,&node[i].b);
    }
    sort(node,node+n,cmp);
    long long flag=0;
    for(int i=0;i<n;i++)
    {
        if(node[i].a>=flag)
        {
            flag=node[i].a+node[i].b;
        }
        else
        {
            flag+=node[i].b;
        }
    }
    printf("%lld",flag);
}

这题是真的狗,开始%d没过,改成%lld就过了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值