Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func findMaxMoney(_ arr: [(Int, Int, Int)]) -> Int{
- var sorted = arr.sorted{
- $0.0 < $1.0
- }
- var dp = [Int](repeating: 0 ,count : arr.count)
- for (index, cur) in sorted.enumerated(){
- dp[index] = cur.2
- for i in 0 ..< index{
- let pre = sorted[i]
- if pre.1 <= cur.0 {
- dp[index] = max(dp[index], dp[i] + cur.2)
- }
- }
- }
- var res = 0
- for p in dp {
- res = max(res, p)
- }
- return res
- }
- var input=[(1,6,400),(2,4,200),(4,8,200),(6,8,250),(5,7,300),(6,10,300)];
- //var input1=[['2-4','100'],['4-8','200'],['5-7','300']];
- let res = findMaxMoney(input)
- print(res)
Add Comment
Please, Sign In to add comment