fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #undef int
  5. int main()
  6. {
  7. #define int long long int
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. cout.tie(0);
  11.  
  12. int n;
  13. cin>>n;
  14. string str;
  15. cin>>str;
  16. vector<int> x(n), v(6);
  17. int temp = 0, cnt = 0;
  18. for(int i = 0;i<str.length();i++)
  19. {
  20. if(str[i]==',')x[cnt++] = temp, temp = 0;
  21. else temp = 10*temp+(str[i]-'0');
  22. }
  23. sort(x.begin(), x.end());
  24. for(int i = 1;i<=6;i++)
  25. v[6-i] = x[n-i];
  26. int ans = 0;
  27. do
  28. {
  29. vector<int> t(5);
  30. for(int i = 0;i<5;i++)
  31. t[i] = v[i]+v[i+1];
  32. for(int i = 0;i<4;i++)
  33. t[i] += t[i+1];
  34. for(int i = 0;i<3;i++)
  35. t[i] += t[i+1];
  36. ans = max(ans, (t[0]+t[1])*(t[1]+t[2]));
  37. }while(next_permutation(v.begin(), v.end()));
  38. cout<<ans<<endl;
  39.  
  40. return 0;
  41. }
Runtime error #stdin #stdout #stderr 0s 80768KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc