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)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
2908 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
2908 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
2908 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
2908 KB |
Execution failed because the return code was nonzero |
2 |
Halted |
0 ms |
0 KB |
- |