Open Credit System
Input: Standard Input

Output: Standard Output

In an open credit system, the students can choose any course they like, but there is a problem. Some of the students are more senior than other students. The professor of such a course has found quite a number of such students who came from senior classes (as if they came to attend the pre requisite course after passing an advanced course). But he wants to do justice 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. He wants to know the maximum amount of score that a senior student gets more than any junior student. For example, if a senior student gets 80 and a junior student gets 70, then this amount is 10. Be careful that we don't want the absolute 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 in the course. This value can be as large as 100,000 and as low as 2. Next n lines contain n integers where the i'th integer is the score of the i'th student. All these integers have absolute values less than 150000. If i < j, then i'th student is senior to the j'th student.

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

Sample Input                             Output for Sample Input

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

 

80
3
-1

 #include <cstdio>
#include <algorithm>
using namespace std; int a[], n; int main()
{
int T;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
for(int i = ; i < n; i++) scanf("%d", &a[i]);
int ans = a[] - a[];
int Max = a[]; //动态维护i之前的最大值
for(int i = ; i < n; i++)
{
ans = max(ans, Max - a[i]);
Max = max(a[i], Max);
}
printf("%d\n", ans);
}
return ;
}

dp


Problemsetter: Mohammad SajjadHossain

Special Thanks: Shahriar Manzoor

Open Credit System的更多相关文章

  1. 【UVA 11078】BUPT 2015 newbie practice #2 div2-A -Open Credit System

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/A In an open credit system, the ...

  2. Uva----------(11078)Open Credit System

    Open Credit System Input:Standard Input Output: Standard Output In an open credit system, the studen ...

  3. UVA 11078 Open Credit System(扫描 维护最大值)

    Open Credit System In an open credit system, the students can choose any course they like, but there ...

  4. Open Credit System(UVA11078)

    11078 - Open Credit System Time limit: 3.000 seconds Problem E Open Credit System Input: Standard In ...

  5. UVA Open Credit System Uva 11078

    题目大意:给长度N的A1.....An 求(Ai-Aj)MAX 枚举n^2 其实动态维护最大值就好了 #include<iostream> #include<cstdio> u ...

  6. uva11078 - Open Credit System(动态维护关键值)

    这道题使用暴力解法O(n*n)会超时,那么用动态维护最大值可以优化到O(n).这种思想非常实用. #include<iostream> #include<cstdio> #in ...

  7. UVa 11549 Open Credit System

    题意:给出n个数,找出两个整数a[i],a[j](i < j),使得a[i] - a[j]尽量大 从小到大枚举j,在这个过程中维护a[i]的最大值 maxai晚于ans更新, 可以看这个例子 1 ...

  8. Java基础之线程——使用执行器(UsingExecutors)

    控制台程序. 在这个版本的银行示例中,把借款和贷款事务创建为在不同线程中执行的任务,它们把事务提交给职员.创建事务的任务是Callable<>任务,因为它们需要返回已为每个账户创建的借款或 ...

  9. 高效算法——M 扫描法

    In an open credit system, the students can choose any course they like, but there is a problem. Some ...

随机推荐

  1. 移动APP为什么要开发两套Android和IOS-桥接模式

    一.前言 现在用H5开发个 web app 多么方便,兼容两大系统Andriod和IOS.但是为什么许多公司还要开发原生的APP?开发原生的APP就需要开发两套一套运行在Andriod系统的,一套运行 ...

  2. 【转载】cocs2dx中c++与c#互调

    文章有参考http://www.cnblogs.com/zhxilin/archive/2013/03/20/2971331.html 下面以接入九幽数据统计插件为例 Step 1:如果是cocos2 ...

  3. Mediator Pattern --中介者模式原理及实现(C++)

    主要参考<大话设计模式>和<设计模式:可复用面向对象软件的基础>两本书.本文介绍中介者模式的实现. 中介者模式:What it is:Define an object that ...

  4. css限制图片大小,避免页面撑爆

    /*==========限制图片大小======避免页面撑暴========*/img { max-width:100%;width:expression(width>669?"100 ...

  5. jquery hasClass、removeClass、addClass方法

    hasClass(class) 检查当前的元素是否含有某个特定的类,如果有,则返回true. 参数: class:用于匹配的类名. ---------------------------------- ...

  6. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  7. Javascript基础系列之(四)数据类型 (数组 array)

    字符串,数值,布尔值都属于离散值(scalar),如果某个变量是离散的,那么任何时候它只有一个值. 如果想使用变量存储一组值,就需要使用数组(array). 数组是由多个名称相同的树值构成的集合,集合 ...

  8. Timer中schedule()的用法

    schedule的意思(时间表.进度表) timer.schedule(new TimerTask(){ void run()},0, 60*60*1000);timer.schedule(new M ...

  9. 【URAL 1917】Titan Ruins: Deadly Accuracy(DP)

    题目 #include<cstdio> #include<algorithm> using namespace std; #define N 1005 int n, m, cn ...

  10. 37.Activity之间的转换以及数据的传递(Intent)学习

      Intent简介:                                                                                在一个Androi ...