A - 予算オーバー / Over Budget 解説 by admin
DeepSeek V3Overview
This problem asks you to compare each project’s allocated budget with its appropriate budget, and find the number of projects that are over budget along with the total amount that needs to be returned.
Analysis
This problem is a straightforward one where you simply need to determine whether \(A_i > B_i\) for each project. Each project can be checked independently, and there is no need to consider relationships between projects. Since the input size can be as large as \(2 \times 10^5\), efficient reading and processing are required, but since each project’s processing completes in constant time, this can be handled without any issues.
Algorithm
- Read the number of projects \(N\)
- For each project, read \(A_i\) and \(B_i\)
- For each project, determine whether \(A_i > B_i\)
- If the condition is met, increment the counter by 1 and add the excess amount \((A_i - B_i)\) to the total
- Output the final counter value and the total excess amount
Complexity
- Time complexity: \(O(N)\)
- Because each of the \(N\) projects is processed in constant time
- Space complexity: \(O(N)\)
- Memory is needed to store the input data
Implementation Notes
Use
sys.stdin.read().split()for efficient reading from standard inputRead all data at once to avoid multiple read operations
Process data sequentially using index management
Use string formatting to format the output
Source Code
import sys
def main():
data = sys.stdin.read().split()
n = int(data[0])
count = 0
total = 0
index = 1
for _ in range(n):
a = int(data[index])
b = int(data[index + 1])
index += 2
if a > b:
count += 1
total += (a - b)
print(f"{count} {total}")
if __name__ == "__main__":
main()
This editorial was generated by deepseekv3.
投稿日時:
最終更新: