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;
}

总结

水题,不解释


目录
相关文章
|
4月前
|
算法 Python
【轴承故障诊断】一种用于轴承故障诊断的稀疏贝叶斯学习(SBL),两种群稀疏学习算法来提取故障脉冲,第一种仅利用故障脉冲的群稀疏性,第二种则利用故障脉冲的额外周期性行为(Matlab代码实现)
【轴承故障诊断】一种用于轴承故障诊断的稀疏贝叶斯学习(SBL),两种群稀疏学习算法来提取故障脉冲,第一种仅利用故障脉冲的群稀疏性,第二种则利用故障脉冲的额外周期性行为(Matlab代码实现)
387 152
|
3月前
|
监控 算法 固态存储
Ashampoo UnInstaller使用教程!高效彻底的软件卸载助手(附下载)
Ashampoo UnInstaller 可彻底卸载软件并清理残留文件、注册表等,提升系统速度与稳定性。支持批量卸载、程序迁移、安装保护及实时监控,操作简单,是优化电脑性能的高效工具。
287 1
|
12月前
|
人工智能 JavaScript 前端开发
一段 JavaScript 代码,集成网站AI语音助手
根据本教程,只需通过白屏化的界面操作,即可快速构建一个专属的AI智能体。
|
8月前
|
文字识别 Python
python做ocr卡证识别很简单
本示例展示了如何使用 `potencent` 库调用腾讯云 OCR 服务识别银行卡和身份证信息。代码中分别通过本地图片路径 (`img_path`) 和配置文件 (`potencent-config.toml`) 实现了银行卡和身份证的 OCR 识别,并输出结果。测试图片及结果显示了识别效果,需提前配置腾讯云的 `SECRET_ID` 和 `SECRET_KEY`。
Vue3项目打包时开启 Gzip 压缩和移动端调试时开启 vConsole 调试
本文介绍了如何在Vue3项目中配置开启Gzip压缩以减小打包文件体积,并在移动端调试时集成vConsole插件,同时使用webpack-bundle-analyzer插件进行打包分析。
868 0
Vue3项目打包时开启 Gzip 压缩和移动端调试时开启 vConsole 调试
|
JavaScript Java 测试技术
基于Java的超市管理系统的设计与实现(源码+lw+部署文档+讲解等)
基于Java的超市管理系统的设计与实现(源码+lw+部署文档+讲解等)
306 0
|
移动开发 前端开发 HTML5
【基于HTML5的网页设计及应用】——水平导航栏
【基于HTML5的网页设计及应用】——水平导航栏
|
前端开发
css引入方式有几种?link和@import有什么区别?
css引入方式有几种?link和@import有什么区别?
224 0
|
存储 算法 PHP
唯一ID生成原理与PHP实现-雪花算法
唯一ID生成原理与PHP实现-雪花算法
858 0
唯一ID生成原理与PHP实现-雪花算法
|
运维 监控 NoSQL
CacheCloud学习
CacheCloud作为一款可视化方便管理redis的开源软件,可以方便redis集群的管理、开发、监控、运维管理,下面就CacheCloud的代码进行一些整理和学习
727 0