Untitled
unknown
c_cpp
a year ago
407 B
4
Indexable
#include <iostream> #include <algorithm> int main() { int n, m, count{},a; std::cin >> n >> m; int* treasures = new int[n]; for (int i = 0; i < n; i++) { std::cin >> a; if (a > 0) { treasures[count++] = a; } } std::sort(treasures, treasures + count, std::greater<int>()); n = 0; for (int i = 0; i < std::min(count,m); i++) { n += treasures[i]; } std::cout << n; }
Editor is loading...
Leave a Comment