AtCoder Beginner Contest 067 B - Snake Toy
2017-07-17 08:36
295 查看
B - Snake Toy
Time limit : 2sec / Memory limit : 256MBScore : 200 points
Problem Statement
Snuke has N sticks. Thelength of the i-th stick is li.
Snuke is making a snake toy by joining K of
the sticks together.
The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.
Constraints
1≤K≤N≤501≤li≤50
li is
an integer.
Input
Input is given from Standard Input in the following format:N K l1 l2 l3 … lN
Output
Print the answer.Sample Input 1
Copy5 3 1 2 3 4 5
Sample Output 1
Copy12
You can make a toy of length 12 by
joining the sticks of lengths 3, 4 and 5,
which is the maximum possible length.
Sample Input 2
Copy15 14 50 26 27 21 41 7 42 35 7 5 5 36 39 1 45
Sample Output 2
Copy386
题解:排完序后求值即可
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;
map<int,int> mp;
int a[51];
int main()
{
int n,m;
while(cin>>n>>m){
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
int s=0;
for(int i=n-m;i<n;i++){
s+=a[i];
}
cout<<s<<endl;
}
return 0;
}
相关文章推荐
- AtCoder Beginner Contest 067 A - Sharing Cookies
- AtCoder Beginner Contest 067 C - Splitting Pile
- AtCoder Beginner Contest 067 D - Fennec VS. Snuke(树上DFS,博弈)
- AtCoder Beginner Contest 067 D - Fennec VS. Snuke
- AtCoder Beginner Contest 067 D - Fennec VS. Snuke
- AtCoder Beginner Contest 067 C - Splitting Pi
- AtCoder Beginner Contest 070 ABC C++&&python
- 【AtCoder Beginner Contest 074 B】Collecting Balls (Easy Version)
- AtCoder Beginner Contest 084 D - 2017-like Number (区间问题 a[r]-a[l-1])
- AtCoder Beginner Contest 085 D Katana Thrower(贪心)
- 2018.1.29【 AtCoder Beginner Contest 087-D 】解题报告(TLE)(STL,队列)
- AtCoder Beginner Contest 087 D - People on a Line 并查集(区间和问题)
- AtCoder Beginner Contest 086 C - Traveling
- AtCoder Beginner Contest 091 D - Two Sequences
- 【AtCoder Beginner Contest 074 A】Bichrome Cells
- AtCoder Beginner Contest 084 D - 2017-like Number (区间问题 a[r]-a[l-1])
- AtCoder Beginner Contest 085 D - Katana Thrower【贪心】
- 2018.1.29【 AtCoder Beginner Contest 087-C 】解题报告(简单dp)
- AtCoder Beginner Contest 087 D - People on a Line 并查集(区间和问题)
- AtCoder Beginner Contest 088 C Takahashi's Information 【思维枚举】