fork download
  1. #include<iostream>
  2.  
  3. #include<cstdio>
  4.  
  5. #include<cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10.  
  11. {
  12.  
  13. long int n,m,*p,i,min,count;
  14.  
  15. long long int bount;
  16.  
  17. scanf("%ld",&n);
  18.  
  19. while(n--)
  20.  
  21. {
  22.  
  23. scanf("%ld",&m);
  24.  
  25. bount=0;min=100001;
  26.  
  27. p=(long int*)malloc(1000001*sizeof(long int));
  28.  
  29. for(i=0;i<m;i++)
  30.  
  31. {
  32.  
  33. scanf("%ld",(p+i));
  34.  
  35. if(min>(*(p+i)))
  36.  
  37. min=(*(p+i));
  38.  
  39. }
  40.  
  41. count=0;
  42.  
  43. for(i=0;i<m;i++)
  44.  
  45. {
  46.  
  47. if(*(p+i)==min)
  48.  
  49. count++;
  50.  
  51. if(count>1)
  52.  
  53. bount=bount+min;
  54.  
  55. if(*(p+i)!=min)
  56.  
  57. bount=bount+(*(p+i));
  58.  
  59. }
  60.  
  61. bount=bount+2;
  62.  
  63. if(min==1)
  64.  
  65. printf("-1\n");
  66.  
  67. else
  68.  
  69. printf("%lld\n",bount);
  70.  
  71. }
  72.  
  73.  
  74.  
  75. return 0;
  76.  
  77. }
  78.  
  79.  
Success #stdin #stdout 0s 10960KB
stdin
2
2
2 2
1
6
stdout
4
2