fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. int main(){
  6. ll n,x = 0,y,t = 0,mid,ans; cin >> n;
  7. vector<ll> s(n);
  8. for(ll i=0;i<n;i++){
  9. cin >> s[i];
  10. t += s[i];
  11. }
  12. sort(s.begin(),s.end(),greater<>());
  13. mid = (n+1)/2;
  14. for(ll i=0;i<mid;i++) x += s[i];
  15. y = t-x;
  16. ans = x*x + y*y;
  17. cout << ans;
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 5272KB
stdin
4
stdout
Standard output is empty