Open Credit System
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 4 1 2 3 4 |
80 |
#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的更多相关文章
- 【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 ...
- Uva----------(11078)Open Credit System
Open Credit System Input:Standard Input Output: Standard Output In an open credit system, the studen ...
- UVA 11078 Open Credit System(扫描 维护最大值)
Open Credit System In an open credit system, the students can choose any course they like, but there ...
- Open Credit System(UVA11078)
11078 - Open Credit System Time limit: 3.000 seconds Problem E Open Credit System Input: Standard In ...
- UVA Open Credit System Uva 11078
题目大意:给长度N的A1.....An 求(Ai-Aj)MAX 枚举n^2 其实动态维护最大值就好了 #include<iostream> #include<cstdio> u ...
- uva11078 - Open Credit System(动态维护关键值)
这道题使用暴力解法O(n*n)会超时,那么用动态维护最大值可以优化到O(n).这种思想非常实用. #include<iostream> #include<cstdio> #in ...
- UVa 11549 Open Credit System
题意:给出n个数,找出两个整数a[i],a[j](i < j),使得a[i] - a[j]尽量大 从小到大枚举j,在这个过程中维护a[i]的最大值 maxai晚于ans更新, 可以看这个例子 1 ...
- Java基础之线程——使用执行器(UsingExecutors)
控制台程序. 在这个版本的银行示例中,把借款和贷款事务创建为在不同线程中执行的任务,它们把事务提交给职员.创建事务的任务是Callable<>任务,因为它们需要返回已为每个账户创建的借款或 ...
- 高效算法——M 扫描法
In an open credit system, the students can choose any course they like, but there is a problem. Some ...
随机推荐
- Java并发编程-CAS
CAS(Compare and swap)比较和替换是设计并发算法时用到的一种技术.简单来说,比较和替换是使用一个期望值和一个变量的当前值进行比较,如果当前变量的值与我们期望的值相等,就使用一个新值替 ...
- [BZOJ 1295][SCOI2009]最长距离(SPFA+暴力)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1295 分析:很巧妙的一道spfa从搜索的角度是搜索在所有1中搜索删除哪T个1,对整个图询问,这 ...
- ThinkPHP之数据库操作
Model文件位置 ThinkPHP使用的是MVC架构,所以我们我们在操作数据库时,首先需要创建自己的Model类. 在每个模块下有个Model文件夹,我们可以将Model类放置在该文件夹下.如果多个 ...
- java中的File类
File类 java中的File类其实和文件并没有多大关系,它更像一个对文件路径描述的类.它即可以代表某个路径下的特定文件,也可以用来表示该路径的下的所有文件,所以我们不要被它的表象所迷惑.对文件的真 ...
- C#基础知识系列七(base、this、new、override、abstract、virtual、static)
前言 本文主要来讲解一下C#中,自己觉得掌握的不怎么样或者用的不多,不太熟悉的关键字,主要包括base.this.new.override.abstract.virtual以及针对static字段和s ...
- 第二十四课:jQuery.event.remove,dispatch的源码解读
本课还是来讲解一下jQuery是如何实现它的事件系统的.这一课我们先来讲一下jQuery.event.remove的源码解读. remove方法的目的是,根据用户传参,找到事件队列,从里面把匹配的ha ...
- Linux下SVN安装配置
第一章 安装 1. 采用源文件编译安装.源文件共两个,为:subversion-1.6.1.tar.gz (subversion 源文件)subversion-deps-1.6.1.tar.gz ...
- java操作xm——添加、修改、删除、遍历
package com.xml.zh; import javax.xml.parsers.*; import javax.xml.transform.Transformer; import javax ...
- 在Eclipse 中安装插件 Activiti
(1)在eclipse中菜单help->Install New software中,点击add (2)输入要安装的插件的名字和路径 Name:Activiti BPMN 2.0 designer ...
- C# 中的多线程
参考网站http://blog.gkarch.com/topic/threading.html