Cod sursa(job #2515564)
Utilizator | Data | 28 decembrie 2019 20:37:32 | |
---|---|---|---|
Problema | Cautare binara | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<bits/stdc++.h>
using namespace std;
int main(){
long int n;long int s=0;cin>>n;long int ln[n];for(long int a=0;a<n;a++){cin>>ln[a];s+=ln[a];}long int sx,sy=0;
sort(ln,ln+n);
if(n%2==0){
for(long int b=0;b<n/2;b++)sy+=ln[b];}
else{
for(long int c=0;c<(n-1)/2;c++)sy+=ln[c];}
sx=s-sy;unsigned long long int res=sx*sx+sy*sy;
cout<<res<<endl;
return 0;
}