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. mysql使用基础 sql语句(一)

    csdn博文地址:mysql使用基础 sql语句(一)  点击进入 命令行输入mysql -u root -p,回车再输入密码,进入mysql. 终端命令以分号作为一条语句的结束,可分为多行输入,只需 ...

  2. IOS判断app在appstore是否有可用的更新

    iTunes可以提供app的版本信息,主要通过appid获取,如 http://itunes.apple.com/lookup?id=946449501,使用时只需要到iTunes查找自己的appid ...

  3. 学习之路三十五:Android和WCF通信 - 大数据压缩后传输

    最近一直在优化项目的性能,就在前几天找到了一些资料,终于有方案了,那就是压缩数据. 一丶前端和后端的压缩和解压缩流程 二丶优点和缺点 优点:①字符串的压缩率能够达到70%-80%左右 ②字符串数量更少 ...

  4. Moqui学习Day2

    用户 本地化  消息和日志门面 用户门面用于管理当前用户和访问,登陆,授权及登出的信息.用户信息包括区域设置,时区以及币种/ec.user.nowTimestamp设置日期. 消息门面用于追踪用户的消 ...

  5. 2016 版 Laravel 系列入门教程(二)【最适合中国人的 Laravel 教程】

    本教程示例代码见: https://github.com/johnlui/Learn-Laravel-5 在任何地方卡住,最快的办法就是去看示例代码. 本篇文章中,我将跟宝宝们一起学习 Laravel ...

  6. 完美实现开机启动虚拟WIFI,顺便实现目前的WP8系统使用VPN(7.1修)

    众所周知,windows7系统的机器若带有无线网卡(台式机可以买一个USB无线网卡,京东目前39元,TP-Link的),可以虚拟出wifi,供手机等移动设备使用. 虚拟的WIFI的命了和软件在网上都找 ...

  7. 这些天自身努力的体会,关于java方面的

    以前也是接触过java,这学期的软件工程课和周围同学各种比赛取得不错的成绩,确实令人倍感压力.为此这几天使劲脑补了一下java的知识,甚至不惜为此翘课,了解了java中的网络编程,对于sokectse ...

  8. Centos下apache启动时httpd: apr_sockaddr_info_get() failed for 报错

    今天安装Apache httpd web服务器时,从官方网站上http://www.apache.org/dyn/closer.cgi下载httpd,然后在centos下解压,安装过程分为三部分: ( ...

  9. Java基础-序列化

    Java序列化是将一个对象编码成一个字节流,反序列化将字节流编码转换成一个对象. 序列化是Java中实现持久化存储的一种方法: 为数据传输提供了线路级对象表示法. Java的序列化机制是通过在运行时判 ...

  10. Learn sed using these command on Linux(流线式编辑器——sed)

    是对文件中的每一行进行处理,不会对源文件进行修改 sed --version sed '11d' sed_file sed -n '/[Bb]erry/p' sed_file (由于设置了n,所以只打 ...