题目描述
一个公交车经过n个站点,乘客从前门上车,从后门下车。
现在统计了在第i个站,下车人数a[i],以及上车人数b[i]。
问公交车运行时候车上最多有多少乘客?
主要思路:
暴力是神。
见代码:
import java.util.Scanner;
/**
* 公交车乘客
*/
public class Main{
public static void main(String[] args) {
int count = 0;
int max = 0;
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
for(int i = 0; i < num ;i++){
//减去下车的人
count -= scanner.nextInt();
//加上上车的人
count += scanner.nextInt();
max = Math.max(count,max);
}
System.out.println(max);
}
}