2021-09-02 14:21
The University of Sydney 前端工程师 kiikor:第一题
#include<iostream>
(5488)#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int size,n;
int sum = 0;
cin >> size;
vector<int> arr(size);
for (int i = 0; i < size; i++)
{
cin >> arr[i];
}
sort(arr.begin(), arr.end());
arr.erase(unique(arr.begin(), arr.end()),arr.end());
cin >> n;
if ((n - 1) >= (arr.size() - n))
cout << "-1" << endl;
else
{
for (int i = 0; i < n ; i++)
{
sum += arr[i];
}
for (int i = arr.size() - n ; i < arr.size() ; i++)
{
sum += arr[i];
}
cout << sum << endl;
}
}
投递华为等公司10个岗位 >
0 点赞 评论 收藏
分享
关注他的用户也关注了: