UVa 11078 Open Credit System

本题可以边读边计算,MaxAi用来维护已经读入的数据的最大值,然后每次读入一个num,就计算一次MaxAi-num,如果比ans更大,就更新ans。

 

 1 //#define LOCAL
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 using namespace std;
 6 
 7 int main(void)
 8 {
 9     #ifdef LOCAL
10         freopen("11078in.txt", "r", stdin);
11     #endif
12 
13     int T;
14     scanf("%d", &T);
15     while(T--)
16     {
17         int n, MaxAi, ans = -999999, num, i;
18         scanf("%d", &n);
19         scanf("%d", &num);
20         MaxAi = num;
21         for(i = 2; i <= n; ++i)
22         {
23             scanf("%d", &num);
24             ans = max(ans, MaxAi - num);
25             MaxAi = max(MaxAi, num);
26         }
27         printf("%d\n", ans);
28     }
29     return 0;
30 }
代码君

 

转载于:https://www.cnblogs.com/AOQNRMGYXLMV/p/3886470.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值