fork download
  1. //sample code
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <cmath>
  5. #include <string>
  6. #include <list>
  7. #include <vector>
  8. #include <algorithm>
  9. #include <functional>
  10. #include <utility>
  11. #include <set>
  12. #include <map>
  13. #include <complex>
  14. #include <queue>
  15. #include <stack>
  16. #include <cstdlib>
  17. #include <ctime>
  18. #include <cstring>
  19. #include <string.h>
  20.  
  21. using namespace std;
  22.  
  23. typedef unsigned int uint;
  24. typedef long long int64;
  25. typedef unsigned long long uint64;
  26. typedef unsigned short ushort;
  27. typedef unsigned char uchar;
  28. typedef pair<int,int> ipair;
  29. typedef vector<int> VI;
  30. typedef vector<string> VS;
  31. typedef vector<double> VD;
  32. #define SIZE(A) ((int)(A.size()))
  33. #define LENGTH(A) ((int)(A.length()))
  34. #define MP(A,B) make_pair(A,B)
  35. const double pi=acos(-1.0);
  36. const double eps=1e-11;
  37. #define FOR(i,a,b) for(int i=(a);i<=(b);++i)
  38. #define REP(i,a) for(int i=0;i<(a);++i)
  39. #define ALL(a) (a).begin(),(a).end()
  40.  
  41. template<class T> T sqr(const T &x) { return x*x; }
  42. template<class T> T lowbit(const T &x) { return (x^(x-1))&x; }
  43. template<class T> int countbit(const T &n) { return (n==0)?0:(1+countbit(n&(n-1))); }
  44. template<class T> void ckmin(T &a,const T &b) { if (b<a) a=b; }
  45. template<class T> void ckmax(T &a,const T &b) { if (b>a) a=b; }
  46.  
  47.  
  48. int main()
  49. {
  50. unsigned long tc, N,K,D,M,sum,ele,a;
  51. scanf("%d",&tc);
  52. VI V;
  53. while(tc--)
  54. {
  55. scanf("%lu%lu%lu%lu",&a, &K, &D, &M);
  56. sum =0;
  57. //cout<<a<<endl;
  58.  
  59. for(int i=0;i<(a);++i)
  60. {
  61. scanf("%lu",&ele);
  62. //cout<<ele<<" ";
  63. sum = sum +ele;
  64. V.push_back(ele);
  65.  
  66. }
  67. //cout<<sum<<endl;
  68. sort(V.begin(),V.begin()+N);
  69. // cout<<V[4]<<endl;
  70.  
  71. cout<<((sum-V[1])*M)<<endl;
  72. }
  73.  
  74. return 0;
  75. }
Success #stdin #stdout 0s 3420KB
stdin
1
5 1 2 10
1 2 3 4 5
stdout
130