Problem E
Open Credit System
Input: Standard Input
Output: Standard Output
In an open credit system, the students can chooseany course they like, but there is a problem. Some of the students are moresenior than other students. The professor of such a course has found quite anumber of such students who came from senior classes (as if they came to attendthe pre requisite course after passing an advanced course). But he wants to dojustice 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. Hewants to know the maximum amount of score that a senior student gets more thanany junior student. For example, if a senior student gets 80 and a juniorstudent gets 70, then this amount is 10. Be careful that we don't want theabsolute 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 inthe course. This value can be as large as 100,000 and as low as 2. Next n lines contain n integers where thei'th integer is the score of the i'thstudent. All these integers have absolute values less than 150000. Ifi < j, then i'thstudent is senior to the j'th student.
Output
For each test case, output the desired number in a newline. Follow the format shown in sample input-output section.
SampleInput Outputfor Sample Input
3 2 100 20 4 4 3 2 1 4 1 2 3 4 | 80 |
Problemsetter: Mohammad Sajjad Hossain
Special Thanks: Shahriar Manzoor
扫描一遍即可,同时维护前面的最大值
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <set>
using namespace std;
#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#endif
const int INF = 0x3f3f3f3f;
const int maxn = 100 + 10;
int main() {
int T;
scanf("%d", &T);
while(T--) {
int n;
int ans = -INF;
int tmax;
scanf("%d%d", &n, &tmax);
for(int i=1; i<n; i++) {
int t;
scanf("%d", &t);
if(tmax - t > ans) {
ans = tmax - t;
}
tmax = max(tmax, t);
}
printf("%d\n", ans);
}
return 0;
}