Official

A - 出発までの準備 / Preparations Before Departure Editorial by admin

GPT 5.2 High

Overview

Starting from time \(S\):00, you perform a total of \(N\) tasks without any breaks. The problem asks you to determine whether all tasks finish by the deadline of \(T\):00, based solely on the total work time.

Analysis

The key insight is that “even if you change the order of tasks, the time when everything finishes does not change.”
This is because the tasks are performed consecutively without breaks, so the total time required to finish is always \(\sum_{i=1}^{N} A_i\) minutes, which is constant.

If you naively try to figure out “which order meets the deadline” by exhaustive search (trying all permutations), the number of cases can be astronomically large, up to \(N!=100!\), which obviously cannot be executed (TLE). However, in this problem, there is no difference based on ordering in the first place, so exhaustive search is entirely unnecessary.

Therefore: - Available time (in minutes) = \((T - S)\times 60\) - Total work time (in minutes) = \(\sum A_i\)

Compare these two values: if the total is within the limit, output Yes; if it exceeds it, output No.

Example: If \(S=9, T=10\), the available time is \(60\) minutes. If the total work time is \(55\) minutes, it fits so the answer is Yes; if it is \(61\) minutes, the answer is No.

Algorithm

  1. Read \(N, S, T\) and the array \(A\) from input.
  2. Compute the total work time \(total = \sum A_i\).
  3. Convert the available time until the deadline to minutes: \(limit = (T - S)\times 60\).
  4. If \(total \le limit\), output Yes; otherwise, output No.

Complexity

  • Time complexity: \(O(N)\) (just computing the sum)
  • Space complexity: \(O(N)\) (for storing the array \(A\); can be reduced to \(O(1)\) if you only maintain the running sum)

Implementation Notes

  • Since the times are given in “hours,” convert them to minutes before comparison (\((T-S)\times 60\)).

  • The condition is “by exactly \(T\):00,” so use <= instead of < for the comparison.

    Source Code

import sys

def main():
    data = sys.stdin.read().strip().split()
    if not data:
        return
    N, S, T = map(int, data[:3])
    A = list(map(int, data[3:3+N]))
    total = sum(A)
    limit = (T - S) * 60
    print("Yes" if total <= limit else "No")

if __name__ == "__main__":
    main()

This editorial was generated by gpt-5.2-high.

posted:
last update: