Guest User

Untitled

a guest
Dec 17th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4.  
  5. using namespace std;
  6.  
  7. /*
  8. 시간복잡도 : O(N * logN)
  9. 공간복잡도 : O(N)
  10. */
  11.  
  12. bool compare(int& a, int& b)
  13. {
  14. return a > b;
  15. }
  16.  
  17. int main()
  18. {
  19. int n;
  20. cin >> n;
  21. vector<int> rope(n);
  22. for (int i = 0; i < n; i++)
  23. cin >> rope[i];
  24.  
  25. //내림차순 정렬
  26. sort(rope.begin(), rope.end(), compare);
  27. int ans = 0;
  28. for (int i = 0; i < n; i++)
  29. ans = max(ans, rope[i] * (i + 1));//i번째 로프로 견딜 수 있는 최대 중량(arr[i] * (i+1))
  30.  
  31. cout << ans;
  32. return 0;
  33. }
Add Comment
Please, Sign In to add comment