반응형
문제 출처 :
https://www.codeground.org/practice/practiceProblemList
알고리즘 분석 :
문제 해결에 필요한 사항
1. 정렬
값을 입력 받고 -> 그 값을 내림차순으로 정렬 -> 공부할 수 있는 과목수 만큼 for문을 돌리고 sum에 누적 합 시킨다.
솔직히 너무 쉬운 문제라 설명할 내용이 없다.
소스 코드 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <iostream> #include <cstdio> #include <algorithm> using namespace std; int arr[200002]; bool comp(const int &a, const int &b) { return a > b; } int main() { int tc; scanf("%d", &tc); for (int tCase = 1; tCase <= tc; tCase++) { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &arr[i]); sort(arr, arr + n, comp); int sum = 0; for (int i = 0; i < m; i++) sum += arr[i]; printf("Case #%d\n%d\n", tCase, sum); } return 0; } // This source code Copyright belongs to Crocus // If you want to see more? click here >> | Crocus |
반응형
'Applied > 알고리즘 문제풀이' 카테고리의 다른 글
[Codeground 12번] 방속의 거울 (0) | 2017.05.10 |
---|---|
[Codeground 4번] 다트 게임 (0) | 2017.05.10 |
[Codeground 2번] 프로그래밍 경진대회 (0) | 2017.05.09 |
[3006번] 터보소트 (0) | 2017.05.06 |
[10986번] 나머지 합 (0) | 2017.05.04 |