def maximize_exhibition_value(N, artworks):
# Sort artworks by their size A
artworks.sort()
max_value = float('-inf')
current_sum = 0
left = 0
for right in range(N):
current_sum += artworks[right][1]
# Get current Amax and Amin
A_max = artworks[right][0]
A_min = artworks[left][0]
# Calculate current value
current_value = current_sum - (A_max - A_min)
max_value = max(max_value, current_value)
# Adjust the left pointer to try minimizing Amax - Amin
while A_max - A_min > 0 and left < right:
current_sum -= artworks[left][1]
left += 1
A_min = artworks[left][0]
current_value = current_sum - (A_max - A_min)
max_value = max(max_value, current_value)
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 |
Correct |
11 ms |
2908 KB |
Output is correct |
2 |
Correct |
10 ms |
2876 KB |
Output is correct |
3 |
Correct |
12 ms |
2912 KB |
Output is correct |
4 |
Correct |
15 ms |
2880 KB |
Output is correct |
5 |
Incorrect |
12 ms |
2908 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2908 KB |
Output is correct |
2 |
Correct |
10 ms |
2876 KB |
Output is correct |
3 |
Correct |
12 ms |
2912 KB |
Output is correct |
4 |
Correct |
15 ms |
2880 KB |
Output is correct |
5 |
Incorrect |
12 ms |
2908 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2908 KB |
Output is correct |
2 |
Correct |
10 ms |
2876 KB |
Output is correct |
3 |
Correct |
12 ms |
2912 KB |
Output is correct |
4 |
Correct |
15 ms |
2880 KB |
Output is correct |
5 |
Incorrect |
12 ms |
2908 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2908 KB |
Output is correct |
2 |
Correct |
10 ms |
2876 KB |
Output is correct |
3 |
Correct |
12 ms |
2912 KB |
Output is correct |
4 |
Correct |
15 ms |
2880 KB |
Output is correct |
5 |
Incorrect |
12 ms |
2908 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |