Tram

简介: Tram

文章目录

一、Tram

总结


一、Tram

本题链接:Tram


题目:

A. Tram

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram’s movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.


Your task is to calculate the tram’s minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.


Input

The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram’s stops.


Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram’s movement.


The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0.

At the last stop, all the passengers exit the tram and it becomes empty. More formally, .

No passenger will enter the train at the last stop. That is, bn = 0.

Output

Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).


Examples


input

4

0 3

2 5

4 2

4 0

output

6


Note

For the first example, a capacity of 6 is sufficient:


At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.

At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now.

At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now.

Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.

Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.


本博客给出本题截图:

image.png

image.png

题意:输出车上最多时候人的数目

AC代码

#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1010;
int a[N],b[N];
int res, cnt;
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++ )
        cin >> a[i] >> b[i];
    for (int i = 0; i < n; i ++ )
    {
        cnt = cnt - a[i] + b[i];
        res = max(res, cnt);
    }
    cout << res << endl;
    return 0;
}

总结

水题,不解释


目录
相关文章
Magnets
Magnets
119 0
Magnets
Anton and Danik
Anton and Danik
92 0
Anton and Danik
Nearly Lucky Number
Nearly Lucky Number
117 0
Nearly Lucky Number
Wrong Subtraction
Wrong Subtraction
67 0
Wrong Subtraction
Translation
Translation
156 0
Translation
|
15天前
|
存储 人工智能 弹性计算
阿里云弹性计算_加速计算专场精华概览 | 2024云栖大会回顾
2024年9月19-21日,2024云栖大会在杭州云栖小镇举行,阿里云智能集团资深技术专家、异构计算产品技术负责人王超等多位产品、技术专家,共同带来了题为《AI Infra的前沿技术与应用实践》的专场session。本次专场重点介绍了阿里云AI Infra 产品架构与技术能力,及用户如何使用阿里云灵骏产品进行AI大模型开发、训练和应用。围绕当下大模型训练和推理的技术难点,专家们分享了如何在阿里云上实现稳定、高效、经济的大模型训练,并通过多个客户案例展示了云上大模型训练的显著优势。
|
19天前
|
存储 人工智能 调度
阿里云吴结生:高性能计算持续创新,响应数据+AI时代的多元化负载需求
在数字化转型的大潮中,每家公司都在积极探索如何利用数据驱动业务增长,而AI技术的快速发展更是加速了这一进程。
|
10天前
|
并行计算 前端开发 物联网
全网首发!真·从0到1!万字长文带你入门Qwen2.5-Coder——介绍、体验、本地部署及简单微调
2024年11月12日,阿里云通义大模型团队正式开源通义千问代码模型全系列,包括6款Qwen2.5-Coder模型,每个规模包含Base和Instruct两个版本。其中32B尺寸的旗舰代码模型在多项基准评测中取得开源最佳成绩,成为全球最强开源代码模型,多项关键能力超越GPT-4o。Qwen2.5-Coder具备强大、多样和实用等优点,通过持续训练,结合源代码、文本代码混合数据及合成数据,显著提升了代码生成、推理和修复等核心任务的性能。此外,该模型还支持多种编程语言,并在人类偏好对齐方面表现出色。本文为周周的奇妙编程原创,阿里云社区首发,未经同意不得转载。
|
23天前
|
缓存 监控 Linux
Python 实时获取Linux服务器信息
Python 实时获取Linux服务器信息
|
9天前
|
人工智能 自然语言处理 前端开发
什么?!通义千问也可以在线开发应用了?!
阿里巴巴推出的通义千问,是一个超大规模语言模型,旨在高效处理信息和生成创意内容。它不仅能在创意文案、办公助理、学习助手等领域提供丰富交互体验,还支持定制化解决方案。近日,通义千问推出代码模式,基于Qwen2.5-Coder模型,用户即使不懂编程也能用自然语言生成应用,如个人简历、2048小游戏等。该模式通过预置模板和灵活的自定义选项,极大简化了应用开发过程,助力用户快速实现创意。