728x90
날이 지나면서 가장 크게 자라는 나무를 가장 늦게 잘라야 최대한 많은 나무를 얻을 수 있다.
나무가 자라는 양을 기준으로 정렬 후 날짜별로 수확할 수 있는 나무의 양을 계산하면 된다.
전체코드
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
ll res;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
int n;
cin >> n;
vector<pii> tree(n);
for (auto &x : tree)
cin >> x.second;
for (auto &y : tree)
cin >> y.first;
sort(tree.begin(), tree.end());
for (int i = 0; i < n; ++i)
res += tree[i].first * i + tree[i].second;
cout << res;
}
|
cs |
728x90
'백준 > 그리디' 카테고리의 다른 글
[ICPC] 백준 1700 - 멀티탭 스케줄링 (0) | 2021.02.06 |
---|---|
[COCI] 백준 9935 - 문자열 폭발 (0) | 2020.11.15 |
백준 1285 - 동전 뒤집기 (0) | 2020.07.10 |
백준 17420 - 깊콘이 넘쳐흘러 (0) | 2020.07.09 |
백준 1082 - 방 번호 (0) | 2020.07.08 |