def fractionalKnapsack(items, capacity):
    weightTaken = 0
    profit = 0

    items.sort(key=lambda x: x[0] / x[1], reverse=True)

    for vi, wi in items:
        if weightTaken + wi <= capacity:
            weightTaken += wi
            profit += vi
        else:
            remaining = capacity - weightTaken
            profit += remaining * (vi / wi)
            break

    return profit


# Example
items = [(60, 10), (100, 20), (120, 30)]  # (value, weight)
capacity = 50

print("Maximum Profit =", fractionalKnapsack(items, capacity))