fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int c[100005];
  7.  
  8. int main() {
  9. long long int n, x, s=0;
  10. scanf("%lld%lld", &n, &x);
  11. for(int i=0; i<n; i++) scanf("%d", &c[i]);
  12. sort(c, c+n);
  13. for(int i=0; i<n; i++) { s+=c[i]*x; if(x>1) x--; }
  14. printf("%lld", s);
  15. return 0;
  16. }
Success #stdin #stdout 0s 3732KB
stdin
1 1
1
stdout
1