More actions
No edit summary |
No edit summary |
||
| Line 10: | Line 10: | ||
|- | |- | ||
| 박인서 | | 박인서 | ||
| 15학번 | |||
|- | |||
| 15이원준 | |||
| 15학번 | | 15학번 | ||
|} | |} | ||
= 코드 = | = 코드 = | ||
== 박인서 == | == 박인서 == | ||
Revision as of 13:01, 6 July 2016
오늘의 문제
참가자
| 이름 | 학번 |
| 박인서 | 15학번 |
| 15이원준 | 15학번 |
코드
박인서
아이디어 1
#include <iostream>
#include <algorithm>
#include <vector>
bool cmp(int a, int b) {return a>b;}
int main() {
int TC;
int k;
std::cin>>TC;
for(k=1;k<=TC;k++){
int n,m;
std::vector<int> a;
std::cin>>n>>m;
for(int i=0;i<n;i++){
int t;
std::cin>>t;
a.push_back(t);
}
std::sort(a.begin(),a.end(),cmp);
int res=0;
for(int i=0;i<m;i++) res+=a[i];
std::cout<<"Case #"<<k<<std::endl<<res<<std::endl;
}
return 0;
}
아이디어 2
#include <iostream>
#include <algorithm>
#include <queue>
int main() {
int TC;
int k;
std::cin>>TC;
for(k=1;k<=TC;k++){
int n,m;
std::priority_queue<int> a;
std::cin>>n>>m;
for(int i=0;i<n;i++){
int t;
std::cin>>t;
a.push(t);
}
int res=0;
for(int i=0;i<m;i++){
res+=a.top();
a.pop();
}
std::cout<<"Case #"<<k<<std::endl<<res<<std::endl;
}
return 0;
}
아이디어
박인서
- 아이디어 1 : 내림차순으로 정렬 후 큰 것부터 더해나가는 방식
- 아이디어 2 : priority_queue 이용