Advertisement
YEZAELP

CUBE-016: S-Value

May 19th, 2021
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using lli = long long;
  5. const int N = 2e3;
  6. lli ar[N+10];
  7.  
  8. int main(){
  9.  
  10.     int n;
  11.     scanf("%d", &n);
  12.  
  13.     for(int i=1;i<=2*n;i++) scanf("%lld", &ar[i]);
  14.  
  15.     sort(ar+1, ar+2*n+1);
  16.  
  17.     lli s = 0;
  18.     for(int i=1;i<=n;i++)
  19.         s += (lli) ar[i] * ar[2*n-i+1];
  20.  
  21.     printf("%lld", s);
  22.  
  23.     return 0;
  24. }
  25. // Greedy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement