Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<algorithm>
- using namespace std;
- /*
- 시간복잡도 : O(N * logN)
- 공간복잡도 : O(N)
- */
- bool compare(int& a, int& b)
- {
- return a > b;
- }
- int main()
- {
- int n;
- cin >> n;
- vector<int> rope(n);
- for (int i = 0; i < n; i++)
- cin >> rope[i];
- //내림차순 정렬
- sort(rope.begin(), rope.end(), compare);
- int ans = 0;
- for (int i = 0; i < n; i++)
- ans = max(ans, rope[i] * (i + 1));//i번째 로프로 견딜 수 있는 최대 중량(arr[i] * (i+1))
- cout << ans;
- return 0;
- }
Add Comment
Please, Sign In to add comment