uva 11078 - Open Credit System(水题)

题目链接: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;
}


uva 11078 - Open Credit System(水题)

上一篇:Word Break II


下一篇:Restore IP Addresses