This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import sys
# Define the maximum size of the item list
N = 10**6 + 5
# Read input from a file if provided
input_file = "Flower.inp"
output_file = "Flower.out"
if len(sys.argv) > 1 and sys.argv[1] == 'file':
sys.stdin = open(input_file, 'r')
sys.stdout = open(output_file, 'w')
# Read number of items
n = int(input())
item = [None] * (N)
# Read item pairs
for i in range(1, n + 1):
x, y = map(int, input().split())
item[i] = (x, y)
# Sort items based on the first element of the tuple
item[1:n + 1] = sorted(item[1:n + 1], key=lambda x: x[0])
# Prefix sums
p = [0] * (N)
for i in range(1, n + 1):
p[i] = p[i - 1] + item[i][1]
# Calculate the result
res = 0
for i in range(1, n + 1):
res = max(res, p[i] + item[1][0] - item[i][0])
# Output the result
print(res)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |