https://www.acmicpc.net/problem/16435
16435번: 스네이크버드
첫 번째 줄에 과일의 개수 N (1 ≤ N ≤ 1,000) 과 스네이크버드의 초기 길이 정수 L (1 ≤ L ≤ 10,000) 이 주어집니다. 두 번째 줄에는 정수 h1, h2, ..., hN (1 ≤ hi ≤ 10,000) 이 주어집니다.
www.acmicpc.net
#include <bits/stdc++.h>
using namespace std;
vector<int> kudamono;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m; cin>>n>>m;
//입력받기
for(int i=0; i<n; i++){
int k; cin>>k;
kudamono.push_back(k);
}
//정렬
sort(kudamono.begin(), kudamono.end());
//과일 먹이기
for(int i=0; i<n; i++){
if(kudamono[i] <= m) m++;
else break;
}
cout << m;
return 0;
}
'문제 풀이' 카테고리의 다른 글
[c++] 백준 2294 동전 2 (0) | 2023.03.07 |
---|---|
[c++] 백준 13164 행복 유치원 (0) | 2023.03.07 |
[c++] 백준 1041 주사위 (0) | 2023.03.06 |
[c++] 백준 1461 도서관 (0) | 2023.03.06 |
[c++] 백준 12904 A와 B (0) | 2023.03.04 |