CF1301B-Motarack's Birthday

对于-1而言,取相邻数最大最小中间值即可。

记得考虑非-1的数对答案也有影响。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 int T,minn,maxn,n,k,res,a[110000];
 6 bool suc;
 7 int main()
 8 {
 9     for (scanf("%d",&T);T;T--)
10     {
11         minn = 2000000000;
12         maxn = 0;
13         res = 0;
14         suc = false;
15         scanf("%d",&n);
16         for (int i = 1;i <= n;i++)
17             scanf("%d",&a[i]);
18         for (int i = 1;i <= n;i++)
19             if (a[i] == -1)
20             {
21                 if (i != 1 && a[i - 1] != -1) 
22                 {
23                     maxn = max(maxn,a[i - 1]);
24                     minn = min(minn,a[i - 1]);
25                 }
26                 if (i != n && a[i + 1] != -1)
27                 {
28                     maxn = max(maxn,a[i + 1]); 
29                     minn = min(minn,a[i + 1]);
30                 }
31             }else
32             {
33                 if (i != 1 && a[i - 1] != -1) 
34                     res = max(res,abs(a[i] - a[i - 1]));
35                 if (i != n && a[i + 1] != -1)
36                     res = max(res,abs(a[i] - a[i + 1]));
37                 suc = true;
38             }
39         k = (maxn + minn) / 2;
40         if (suc) 
41             printf("%d %d\n",max(res,max(maxn - k,k - minn)),k);
42         else
43             printf("0 1\n");
44     }
45     return 0;
46 }

 

posted @ 2020-02-16 08:25  IAT14  阅读(181)  评论(0编辑  收藏  举报