I want to sort the inputs and output the sum of the last 5's , but I've encounter an error in the following:
a.cpp:13:36: error: no matching function for call to ‘sort(std::vector<int>::iterator, __gnu_cxx::__alloc_traits<std::allocator<int> >::value_type&)’
sort(weights.begin(),weights.at(n));
The following is my code , how can i fix it?
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   int TotalWeight;
   int cows[100000];
   vector<int> weights(100000);
   cin >> n;
   for (int i = 0; i < n; i++)
   {
      cin >> cows[i];
      weights[i] = cows[i];
   }
   sort(weights.begin(), weights.at(n));
   TotalWeight = weights.at(n - 4) + weights.at(n - 3) + weights.at(n - 2) + weights.at(n - 1) + weights.at(n);
   cout << TotalWeight << endl;
   return 0;
}
 
    