UAV 11078 - Open Credit System

Problem E
Open Credit System
Input:
Standard Input

Output: Standard Output

In an open credit system, the students can chooseany course they like, but there is a problem. Some of the students are moresenior than other students. The professor of such a course has found quite anumber of such students who came from senior classes (as if they came to attendthe pre requisite course after passing an advanced course). But he wants to dojustice to the new students. So, he is going to take a placement test(basically an IQ test) to assess the level of difference among the students. Hewants to know the maximum amount of score that a senior student gets more thanany junior student. For example, if a senior student gets 80 and a juniorstudent gets 70, then this amount is 10. Be careful that we don't want theabsolute value. Help the professor to figure out a solution.

Input
Input consists of a number of test cases T (less than 20). Each case starts with an integer n which is the number of students inthe course. This value can be as large as 100,000 and as low as 2. Next n lines contain n integers where thei'th integer is the score of the i'thstudent. All these integers have absolute values less than 150000. Ifi < j, then i'thstudent is senior to the j'th student.

Output
For each test case, output the desired number in a newline. Follow the format shown in sample input-output section.

SampleInput                             Outputfor Sample Input

3
2
100
20
4
4
3
2
1
4
1
2
3
4
 

80
3
-1


Problemsetter: Mohammad Sajjad Hossain

Special Thanks: Shahriar Manzoor


扫描一遍即可,同时维护前面的最大值


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <set>

using namespace std;

#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#endif


const int INF = 0x3f3f3f3f;
const int maxn = 100 + 10;


int main() {
	int T;

	scanf("%d", &T);
	while(T--) {
		int n;
		int ans = -INF;
		int tmax;
		scanf("%d%d", &n, &tmax);
		for(int i=1; i<n; i++) {
			int t;
			scanf("%d", &t);
			if(tmax - t > ans) {
				ans = tmax - t;
			}
			tmax = max(tmax, t);
		}
		printf("%d\n", ans);
	}

	return 0;
}




 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值