fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7. cin.tie(0);
  8. cout.tie(0);
  9. ios::sync_with_stdio(0);
  10.  
  11. int N;
  12. int answer = 0;
  13. vector<int> a, b;
  14.  
  15. cin>>N;
  16. for(int i=0;i<N;i++){
  17. int number;
  18. cin>>number;
  19. a.push_back(number);
  20. }
  21. for(int i=0;i<N;i++){
  22. int number;
  23. cin>>number;
  24. b.push_back(number);
  25. }
  26. sort(a.begin(), a.end(), greater<int>());
  27. sort(b.begin(), b.end());
  28.  
  29. for(int i=0;i<N;i++){
  30. answer += a[i]*b[i];
  31. }
  32. cout<<answer<<'\n';
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5308KB
stdin
3
1 1 3
10 30 20
stdout
80