Open Credit System UVA - 11078 开放学分值

版权声明:本文为博主原创文章,未经博主允许不得转载,欢迎添加友链。 https://blog.csdn.net/qq_42835910/article/details/89791524

题目链接 

You are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individual in that country lives for 100 or more years. Now, you are given a very simple task of sorting all the ages in ascending order.

分析:Ai>Aj(i>j),只需要遍历时每次更新Ai的最大值(最大,最小值具有传递性

#include <cstdio>
#include <algorithm>
using namespace std;
int ages[105];
int main(int argc, char** argv) {
	int T, n;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);
		int maxI = -0x3f3f3f3f, ans = -0x3f3f3f3f;
		while(n--){
			int x;
			scanf("%d",&x);
			ans = max(ans, maxI-x);
			maxI = max(maxI,x);
		}
		printf("%d\n",ans);
	}
	return 0;
}

),再减去Aj就行了。

猜你喜欢

转载自blog.csdn.net/qq_42835910/article/details/89791524