A - サーバーへのリクエスト分散 / Distributing Requests to Servers Editorial by admin
Qwen3-Coder-480BOverview
This is a problem where you determine whether all requests can be processed by checking if the total processing capacity across all servers is at least the number of campaign days \(M\).
Analysis
In this problem, one request is generated each day, and the goal is to distribute them among \(N\) servers such that no server exceeds its processing capacity.
The key observation is that there is no need to individually consider “the number of requests assigned to each server.” This is because what ultimately matters is only the total sum of processing capacities across all servers.
For example, if there are 3 servers with processing capacities \(A = [3, 2, 1]\) and \(M = 5\), the total processing capacity is \(3 + 2 + 1 = 6\), so 5 requests can be processed.
Conversely, if \(M = 7\), the requests cannot all be processed.
Therefore, there is no need to consider the detailed assignment of which server handles each request — simply computing the total sum and comparing it is sufficient for the determination.
A naive approach might be to greedily assign each day’s request to the server with the most remaining capacity, but since \(M\) can be up to \(10^9\), simulating this process would not finish in time (TLE). However, this complex assignment logic is actually unnecessary, and comparing the total sum alone is sufficient.
Algorithm
- Compute the sum of the processing capacities \(A_i\) of all servers.
- If the sum is at least \(M\), output
Yes; otherwise, outputNo.
Complexity
- Time complexity: \(O(N)\)
- Space complexity: \(O(N)\)
※ Since all elements need to be scanned once to compute the sum, the time complexity is \(O(N)\). The space complexity is also \(O(N)\) because the input array is stored.
Implementation Notes
sys.stdin.readis used for fast input reading.Using a descriptive variable name like
total_capacity = sum(A)instead of justsum(A)improves readability.Note that fast input processing is important for large inputs.
Source Code
import sys
def main():
input = sys.stdin.read
data = input().split()
N = int(data[0])
M = int(data[1])
A = list(map(int, data[2:]))
total_capacity = sum(A)
if total_capacity >= M:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
This editorial was generated by qwen3-coder-480b.
posted:
last update: