uestc OJ 1849Negative People in Da House
来源:互联网 发布:人工智能平台有哪些 编辑:程序博客网 时间:2024/05/17 02:25
Description
The following math joke is presented for your amusement:Two mathematicians sit in a car outside a house. Two people enter the house. Then, three people are observed going out of the house. One of the mathematicians exclaim:If one person is to enter now, the house will be empty!
Since you have very little sense of humor, you are to write a program that will calculate the minimum number of people there must have been there to begin with. In other words, given a sequence of groups of people leaving and entering the house, output the minimum number of people there must have been before you started stalking. After writing this program, your mathematician friend will leave you, as well as their math department, to start a company specializing in joke-telling and stalking.
Input
The fi rst line of the input consists of a single integer T, the number of test cases. Each of the following T cases has two parts: First, a line containing a single integer M. Then follows M lines with two integers P1 and P2 separated by a space, where the rst one contains the number of people entering the house,then the number of people leaving the house. Note that these are two events: First, P1 people enter the house, then P2 people leave the house.
0 < T <= 50
0 < M <= 100
0 <= P1; P2 <= 1000
Output
Output the minimum number of people that would have to have been inside the house at the beginning.
Sample Input
1
3
3 5
3 4
1 0
Sample Output
3
#include<stdio.h>int main(){ int t,m,p,q,bgin,inhouse; scanf("%d",&t); while(t--){ bgin=0;inhouse=0; scanf("%d",&m); while(m--){ scanf("%d%d",&p,&q); if(q>p){ q-=p; if(q>inhouse){q-=inhouse; inhouse=0; bgin+=q;} if(q<=inhouse) inhouse-=q; } else if(q<p) inhouse+=(p-q);} printf("%d\n",bgin);}}
- uestc OJ 1849Negative People in Da House
- BNU33650:Negative People in Da House
- IDIOPEN 2013 D Negative People in Da House
- uestc oj 1793 Kalindrome
- uestc oj 1227 Hotel
- uestc oj 1500 AreYouBusy
- uestc oj 1484 STAMPS
- uestc oj 1272 Sticks
- uestc oj 1230 Picture
- uestc oj 1223 Islands
- uestc oj 1001 DotNotation
- 吐槽 uestc oj
- uestc oj 1876 聚会
- UESTC OJ 1830
- UESTC OJ Windy 数
- Famous people in C++
- People in Computer Vision
- People in Computer Vision
- Linux设备驱动之I/O端口与I/O内存
- MFC加入滚动条
- 快速排序算法
- 大小为0的数组
- getch() vs getchar()
- uestc OJ 1849Negative People in Da House
- CKEditor+CKFinder配置以及使用简介
- extern "C"的作用
- 【林间美女XP热门主题】
- 小应用程序运行结果如下:红色方块在文字上从左向右循环移动。
- ORALCE一个事物的完整分析流程
- Spring的getSession方法造成的数据库不关闭连接
- DUMPBIN命令行
- 矩形交集和并集的面积-离散化