반응형
-문제
1) 비용배열 내림차순 정렬 (제일 오래 걸리는 묘목 먼저 심기)
2) "묘목 심는 날 + 자라는데 걸리는 일수" 중 최댓값 찾기
3) 묘목 다 자라는 날(위의 최댓값) 다음날 이장님 부르기
-코드
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int n, day=1, max=1, tmp;
scanf("%d", &n);
vector<int> cost(n);
for (int i = 0; i < n; i++)
{
scanf("%d", &cost[i]);
}
sort(cost.rbegin(), cost.rend());
for (int i = 0; i < n; i++)
{
tmp = day + cost[i];
if (tmp > max) max = tmp;
day++;
}
printf("%d", max + 1);
return 0;
}
반응형
'이론 > 코딩테스트' 카테고리의 다른 글
[백준] 1246번 온라인 판매 (그리디 알고리즘) (0) | 2022.08.24 |
---|---|
[백준] 11256번 사탕 (그리디 알고리즘) (0) | 2022.08.24 |
[백분] 6550번 부분 문자열 (그리디 알고리즘) (0) | 2022.08.21 |
[백준] 2828번 사과 담기 게임 (그리디 알고리즘) (0) | 2022.08.20 |
[백준] 3135번 라디오 (그리디 알고리즘) (0) | 2022.08.20 |