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

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

  1.  

80
3
-1

  1. #include <cstdio>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int a[], n;
  6.  
  7. int main()
  8. {
  9. int T;
  10. scanf("%d", &T);
  11. while(T--)
  12. {
  13. scanf("%d", &n);
  14. for(int i = ; i < n; i++) scanf("%d", &a[i]);
  15. int ans = a[] - a[];
  16. int Max = a[]; //动态维护i之前的最大值
  17. for(int i = ; i < n; i++)
  18. {
  19. ans = max(ans, Max - a[i]);
  20. Max = max(a[i], Max);
  21. }
  22. printf("%d\n", ans);
  23. }
  24. return ;
  25. }

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. 慢牛股票-基于Sencha+Cordova的股票类APP

    13,14这两年,我的业余时间都花在了移动互联网技术和股票技术分析上,14年底,终于开发完成慢牛,上线小米应用商店.应用宝.百度应用商店.   慢牛是一款数据分析类的股票APP,提供数据订阅和数据分析 ...

  2. MVC采用HtmlHelper扩展和Filter封装验证码的功能

    最近因为有个项目除了登录还有其他很多地方需要用到验证码的功能,所以想到了采用HtmlHelper和ActionFilter封装一个验证码的功能,以便能够重复调用.封装好以后调用很方便,只需在View中 ...

  3. 《1024伐木累》-te别篇,庭审你知道吗?

    思前想后,我觉得不应该发这一期,因为,做完这一期之后突然发觉,自己失去了主题,到底是在讽刺?还是在讽刺?还是在讽刺呢?不论是什么,大家自己判断吧.就当作者不想发表自己的观点,先看这一期的对白吧! 1. ...

  4. 简述WebService的使用(一)

    环境: vs版本:vs2013 windows版本:win7 IIS版本:IIS7.0 (如果觉得对您有用,请点击右下角[推荐]一下,让更多人看到,谢谢) 配置环境: 主要针对于IIS ·首先,有很多 ...

  5. 约瑟夫环的java解决

    总共3中解决方法,1.数学推导,2.使用ArrayList递归解决,3.使用首位相连的LinkedList解决 import java.util.ArrayList; /** * 约瑟夫环问题 * 需 ...

  6. 【Moqui业务逻辑翻译系列】Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和机会

    h1. Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和合作机会 h4. Ideas to incorporat ...

  7. Javascript的io操作

    一.功能实现核心:FileSystemObject 对象 要在javascript中实现文件操作功能,主要就是依靠FileSystemobject对象. 二.FileSystemObject编程 使用 ...

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

    本教程示例代码见: https://github.com/johnlui/Learn-Laravel-5 在任何地方卡住,最快的办法就是去看示例代码. 本文基于 Laravel 5.2 版本,无奈 5 ...

  9. [转]Java中的对象和对象引用实例浅析

    在Java中,有一组名词经常一起出现,它们就是“对象和对象引用”,很多朋友在初学Java的时候可能经常会混淆这2个概念,觉得它们是一回事,事实上则不然.今天我们就来一起了解一下对象和对象引用之间的区别 ...

  10. HTML5的拖拽时间 ondragstart

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...