fork download
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. #define min(x,y) ((x) < (y) ? (x) : (y))
  5. using namespace std;
  6. long long int calc(vector<long long int> ar,char ch,int b);
  7. int main()
  8. {
  9. int n;
  10. scanf("%d",&n);
  11. for(int i=0;i<n;i++)
  12. {
  13. string st;
  14. int b;
  15. vector<long long int> vec;
  16. scanf("%d",&b);
  17. //cin>>st;
  18. int j=0;
  19. for(long long int k=0;k<b;k++)
  20. {
  21. long long int g;
  22. scanf("%lld",&g);
  23. vec.push_back(g);
  24. j=j+2;
  25. }
  26. printf("%lld",min(calc(vec,'*',vec.size()),min(calc(vec,'+',vec.size()),calc(vec,'-',vec.size()))));
  27. }
  28. }
  29. long long int calc(vector<long long int> ar,char ch,int b)
  30. {
  31. if(b==1)
  32. return ar[b-1];
  33. else if(ch=='+')
  34. return calc(ar,'*',b-1)+ar[b-1];
  35. else if(ch=='*')
  36. return calc(ar,'*',b-1)*ar[b-1];
  37. else if(ch=='-')
  38. return calc(ar,'-',b-1)-ar[b-1];
  39.  
  40. }
Success #stdin #stdout 0s 3480KB
stdin
2
3
1 2 3
1
9
stdout
-49