Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update police.cpp #775

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Max-CoderBoi
Copy link

Key Optimizations:
Removed unnecessary array: Instead of storing all values in a[100000], process them one by one. Used a single loop with direct input handling: This reduces memory usage and improves efficiency. Improved condition handling:
If a crime occurs (x == -1), check if a police officer (p > 0) is available. If so, decrement p. Otherwise, increment sum (unhandled crimes). If police officers are recruited (x > 0), simply add them to p.

Key Optimizations:
Removed unnecessary array: Instead of storing all values in a[100000], process them one by one.
Used a single loop with direct input handling: This reduces memory usage and improves efficiency.
Improved condition handling:
If a crime occurs (x == -1), check if a police officer (p > 0) is available.
If so, decrement p. Otherwise, increment sum (unhandled crimes).
If police officers are recruited (x > 0), simply add them to p.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant