답안 #1050360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050360 2024-08-09T08:56:14 Z vjudge1 Art Exhibition (JOI18_art) Python 3
0 / 100
12 ms 2908 KB
def maximize_exhibition_value(N, artworks):
    # Sort artworks by their size A
    artworks.sort()
    
    # Initialize variables
    max_value = float('-inf')
    prefix_sum = [0] * (N + 1)  # To store prefix sums

    # Calculate prefix sums
    for i in range(N):
        prefix_sum[i + 1] = prefix_sum[i] + artworks[i][1]
    
    # Sliding window approach
    left = 0
    for right in range(1, N + 1):
        while left < right:
            A_max = artworks[right - 1][0]
            A_min = artworks[left][0]
            current_value = prefix_sum[right] - prefix_sum[left] - (A_max - A_min)
            max_value = max(max_value, current_value)
            if prefix_sum[right] - prefix_sum[left + 1] - (A_max - artworks[left + 1][0]) >= current_value:
                left += 1
            else:
                break
    
    return max_value

# Input reading
N = int(input().strip())
artworks = []
for _ in range(N):
    A, B = map(int, input().strip().split())
    artworks.append((A, B))

# Calculate and print the result
result = maximize_exhibition_value(N, artworks)
print(result)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 2908 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 2908 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 2908 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 2908 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -