728x90
https://softeer.ai/practice/6288/history?questionType=ALGORITHM
소스코드
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
int bag, n;
cin >> bag >> n;
int m;//무게
int p;//가격
vector<pair<int,int>> pm;
int result = 0;
for (int i = 0; i < n; i++)
{
cin >> m >> p;
pm.push_back({ p,m });
}
sort(pm.begin(), pm.end(), greater<>());
for (int i = 0; i < pm.size(); i++)
{
if (bag >= pm[i].second) {
bag -= pm[i].second;
result += pm[i].first * pm[i].second;
}
else {
result += bag* pm[i].first;
break;
}
}
cout << result;
return 0;
}
728x90
'코딩공부 > Softeer' 카테고리의 다른 글
[Softeer/C++]Level2 8단 변속기 (0) | 2024.03.08 |
---|---|
[Softeer/C++]Level2 바이러스 (0) | 2024.03.08 |
[Softeer/C++]Level2 [한양대 HCPC 2023] X marks the Spot (0) | 2024.03.08 |
[Softeer/C++]Level1 위험한 효도 (0) | 2024.03.08 |
[Softeer/C++]Level1 [한양대 HCPC 2023] Tren del Fin del Mundo (1) | 2024.03.07 |