标签:
Description
Input
Output
Sample Input
2
10 3
2 6 7
214 7
11 12 7 13 176 23 191
Sample Output
4 8
38 207
1 #include<cstdio> 2 #include<cmath> 3 using namespace std; 4 5 int main() 6 { 7 int test; 8 9 scanf("%d",&test); 10 11 while(test--) 12 { 13 int n,L; 14 scanf("%d%d",&L,&n); 15 16 int left=L; 17 int right=0; 18 int mid=L+1; 19 double dis_mid=(double)L/2; 20 21 int cur; 22 23 for(int i=1;i<=n;i++) 24 { 25 scanf("%d",&cur); 26 27 if(cur<left) 28 left=cur; 29 if(cur>right) 30 right=cur; 31 if(abs(cur-dis_mid)<abs(mid-dis_mid)) 32 mid=cur; 33 } 34 35 int min=(L-mid)<mid?(L-mid):mid; 36 int max=(L-left)>left?(L-left):left; 37 if(right>max) 38 max=right; 39 if(L-right>max) 40 max=L-right; 41 42 printf("%d %d\n",min,max); 43 44 } 45 return 0; 46 }
标签:
原文地址:http://www.cnblogs.com/-maybe/p/4470386.html