Official

D - The Middle Day Editorial by en_translator


Follow the instructions of the problem statement to implement it straightforward.

  • Find the total days in a year
    • You can use a for statement to do so.
  • Find the middle day based on the total days
    • Find the month that the middle day belongs with a for statement, and then find what day of the month is the middle day. This can be done with simple comparisons and subtractions.

For more details, see the sample code.

Sample code (Python):

m = int(input())
d = list(map(int,input().split()))

tot = 0
for x in d:
    tot += x

mid = (tot+1) // 2

for i in range(m):
    if mid <= d[i]:
        print(str(i+1) + " " +str(mid))
        exit()
    else:
        mid -= d[i]

posted:
last update: