zoukankan      html  css  js  c++  java
  • UVA-11078 Open Credit System

    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

    开始想着分为前缀最大值和后缀最大值俩数组,求差的最大和。后来发现可以动态的更新,省掉了数组的开销

    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    
    int A[100000];
    
    int main() {
        int T, n;
        scanf("%d", &T);
        while (T--) {
            scanf("%d", &n);
            for (int i = 0; i < n; ++i) {
                scanf("%d", A + i);
            }
            int t = A[0], ans = A[0] - A[1];
            for (int i = 1; i < n; ++i) { //二者同时更新,最大结果值,和最大索引
                ans = max(ans, t - A[i]);
                t = max(t, A[i]);
            }
            printf("%d
    ", ans);
        }
    }
  • 相关阅读:
    cookie,session,django中间件,csrf回顾
    CSRF
    django中间件
    cookie与session
    form组件简单回顾
    分页器组件与form组件
    ajax回顾
    AJAX
    python魔法方法详解
    python静态方法类方法属性方法
  • 原文地址:https://www.cnblogs.com/wangsong/p/7627555.html
Copyright © 2011-2022 走看看