QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#718432 | #9528. New Energy Vehicle | bobfacer | WA | 17ms | 10572kb | Python3 | 2.4kb | 2024-11-06 20:30:35 | 2024-11-06 20:30:36 |
Judging History
answer
import sys
import bisect
def solve():
input = sys.stdin.read().split()
ptr = 0
# Read n and m
n = int(input[ptr]); ptr += 1
m = int(input[ptr]); ptr += 1
# Read a[1..n]
a = [0] * (n + 1)
for i in range(1, n + 1):
a[i] = int(input[ptr])
ptr += 1
# Initialize sum as the sum of all a[i]
total_sum = sum(a)
# Initialize lst array to keep track of last charging station for each battery
lst = [0] * (n + 1)
# Initialize x array to store charging station positions, x[0] = 0
x = [0] * (m + 1)
# Initialize a sorted list to act as the set of intervals
intervals = []
for i in range(1, m + 1):
# Read x[i] and id
x_i = int(input[ptr]); ptr += 1
id_ = int(input[ptr]); ptr += 1
x[i] = x_i
# If the current sum is less than x[i], skip this charging station
if total_sum < x[i]:
continue
# Determine the previous position, x[i-1], with x[0] = 0
x_prev = x[i - 1] if i > 1 else 0
# Insert the new interval into the sorted list
bisect.insort(intervals, (x_prev + 1, x[i]))
# Get the start position from the last charging station of the current battery
st = x[lst[id_]] + 1
cur = a[id_] # Current battery capacity
while True:
# Find the first interval with x1 >= st
index = bisect.bisect_left(intervals, (st, 0))
if index == len(intervals):
break # No such interval found
# Remove the interval from the list
interval = intervals.pop(index)
x1, x2 = interval
distance = x2 - x1 + 1
if cur < distance:
# If the battery cannot cover the entire interval, split it
bisect.insort(intervals, (x1 + cur, x2))
total_sum += cur
break
else:
# If the battery can cover the entire interval
total_sum += distance
cur -= distance
# If the interval ends at the current charging station, stop
if x2 == x[i]:
break
# Update the last charging station for the current battery
lst[id_] = i
# Output the final sum
print(total_sum)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 17ms
memory: 10572kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
result:
wrong answer 1st lines differ - expected: '12', found: ''