http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/A

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 3 2 100 20 4 4 3 2 1 4 1 2 3 4 Sample Output 80 3 -1

题意:给出一串数字,先出现的与后出现的数的最大差值是多少,有t组(少于20)数据,每组最多100,000个数,这些数绝对值小于150000。

题解:每组的n个数,读入的第一个数作为maxn,表示当前出现的最大数,接下来每读一个数,看看用maxn(前面最大的数)减去a(当前数)是否比ans(之前的计算的最大差值)更大,ans=max(ans,maxn-a),然后比较a是否比maxn大,maxn=max(maxn,a)

代码:

#include<cstdio>
#include<algorithm> #define mm=100005; using namespace std; int t,n,a,ans,maxn;
int main(){
scanf("%d",&t);
while(t--){
ans=-;
scanf("%d",&n);
scanf("%d",&maxn);
for(int i=;i<n;i++)
{
scanf("%d",&a);
ans=max(maxn-a,ans);
maxn=max(a,maxn);
}
printf("%d\n",ans);
}
}

  

【UVA 11078】BUPT 2015 newbie practice #2 div2-A -Open Credit System的更多相关文章

  1. 【UVA 401】BUPT 2015 newbie practice #2 div2-B-Palindromes

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/B A regular palindrome is a str ...

  2. 【CodeForces 312B】BUPT 2015 newbie practice #3A Archer

    题 SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the targ ...

  3. 【CodeForces 605A】BUPT 2015 newbie practice #2 div2-E - Sorting Railway Cars

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/E Description An infinitely lon ...

  4. 【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/D The famous Korean internet co ...

  5. 【HDU 4925】BUPT 2015 newbie practice #2 div2-C-HDU 4925 Apple Tree

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/C Description I’ve bought an or ...

  6. 【巧妙算法系列】【Uva 11464】 - Even Parity 偶数矩阵

    偶数矩阵(Even Parity, UVa 11464) 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1,使得每个元素的上.下.左.右的元素(如果存在的话)之和均为偶数.比 ...

  7. 【贪心+中位数】【UVa 11300】 分金币

    (解方程建模+中位数求最短累积位移) 分金币(Spreading the Wealth, UVa 11300) 圆桌旁坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一 ...

  8. 【UVa 10881】Piotr's Ants

    Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...

  9. 【UVa 116】Unidirectional TSP

    [Link]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

随机推荐

  1. python中的深拷贝和潜拷贝

    >>> a = ['ace',['age',10]] >>> b = a[:] >>> c = list(a) >>> for ...

  2. 2014 UESTC 暑前集训队内赛(3) 部分解题报告

    B.Battle for Silver 定理:完全图Kn是平面图当且仅当顶点数n<=4. 枚举所有完全图K1,K2,K3,K4,找出最大总权重. 代码: #include <iostrea ...

  3. Mecanim的Retargeting和BodyMask

    Retargeting(动画重定向) 文档 http://game.ceeger.com/Manual/Retargeting.html 介绍 Mecanim 的最强大的功能之一,重定目标的仿人机器人 ...

  4. Java Executor并发框架(三)ThreadPoolExecutor 队列缓存策略

    前面两篇讲解了线程池中线程创建后的运行情况,其中有一系列的策略来保证线程正常运行.但是我们知道线程池是可以设置容量的,而且这容量的设置也是至关重要的,如果容量设置的太小,那么将会影响系统的运行效率,如 ...

  5. 转: 关于Linux与JVM的内存关系分析

    转自: http://tech.meituan.com/linux-jvm-memory.html Linux与JVM的内存关系分析 葛吒2014-08-29 10:00 引言 在一些物理内存为8g的 ...

  6. [转]curl_multi 实现准多进程发请求

    FROM : http://blog.sina.com.cn/s/blog_515b90d00100jtnv.html curl_multi函数族:curl_multi_closecurl_multi ...

  7. 蒙古人交友网站 www.mengguren.com

    蒙古人交友http://www.mengguren.com/ 经过一个多月的努力,终于上线了,虽然长得丑陋一些.功能简单一些,欢迎大家注册,方便别人能找到您.吉日嘎拉<252056973@qq. ...

  8. C++函数内存占用

    一个类的对象中是没有关于普通成员函数的指针的slot,只有成员变量还有虚表指针,类的成员函数的代码定义在PE文件的代码区,所以从程序加载时,就已经分配好了内存用于存放这些代码:代码运行时所需要的内存, ...

  9. [转]有关WorldWind1.4的worldwind.cs窗口设计器打开错误的解决方法

    Solution for Designer error when opening WorldWind.cs in WW1.4.0 When I load the WW project in my Vi ...

  10. 利用Chrome插件向指定页面植入js,劫持 XSS

    资源来自:http://www.2cto.com/Article/201307/225986.html 首页 > 安全 > 网站安全 > 正文 利用Chrome插件向指定页面植入js ...