728x90
반응형
19709 LunchBox
문제풀이
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void fast_io(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n,m;
int main(void)
{
fast_io();
cin >> n >> m;
vector<int> v(m);
for(int i=0;i<m;i++)
cin >> v[i];
sort(v.begin(),v.end());
int tmp = 0,cnt=0;
for(int i=0;i<m;i++)
{
if(tmp+v[i]<=n)
{
tmp+=v[i];
cnt++;
}
}
cout << cnt;
}
예외처리에 잘 신경써야겠다.
728x90
반응형
'자라는 개발자 > 문제풀이' 카테고리의 다른 글
백준 c++ 16460 Cupid (0) | 2022.08.21 |
---|---|
백준 c++ 15312 이름 궁합 (0) | 2022.08.17 |
백준 c++ 11728 배열 합치기 (0) | 2022.08.15 |
백준 c++ 9933 민균이의 비밀번호 (0) | 2022.08.08 |
백준 c++ 11645 I've Been Everywhere, Man (0) | 2022.07.23 |