Write an algorithm to detect anomalous patterns in user request logs.
Treat a pattern as anomalous when the same user requests the same endpoint at least threshold times within an inclusive time window of window seconds. Implement detect_anomalies(logs, window, threshold), where logs is an unsorted list of dictionaries containing integer timestamp, string user_id, and string endpoint fields. Return each anomalous [user_id, endpoint] pair once, sorted lexicographically. Return an empty list when no pattern is anomalous.
1 <= threshold, 0 <= window; timestamps are integer seconds.
def detect_anomalies(logs, window, threshold):