uva 11078 - Open Credit System(水题)

来源:互联网 发布:linux网络命令大全 编辑:程序博客网 时间:2024/06/06 04:25

题目链接:uva 11078 - Open Credit System


题目大意:给出n个数,找出两个数之间差的最大值,要求num[i] - num[j](i < j)


解题思路:维护最大值Max,每次读取一个数时用Max - c,维护ans。


#include <stdio.h>#include <algorithm>using namespace std;const int INF = 0x3f3f3f3f;int main() {int cas, n;scanf("%d", &cas);while (cas--) {scanf("%d", &n);int ans = -INF, Max = -INF, c;for (int i = 0; i < n; i++) {scanf("%d", &c);ans = max(ans, Max - c);Max = max(Max, c);}printf("%d\n", ans);}return 0;}


0 0