diff --git a/Domains/CompetitiveProgramming/Programs/C++/PoliceRecruits.cpp b/Domains/CompetitiveProgramming/Programs/C++/PoliceRecruits.cpp new file mode 100644 index 00000000..b545d4cd --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/C++/PoliceRecruits.cpp @@ -0,0 +1,61 @@ +/* +Problem: Police Recruits +Platform: Codeforces +Problem Code: 427A +Difficulty: Easy +Link: https://codeforces.com/problemset/problem/427/A + +Problem Statement: +Given a sequence of events representing crimes and police recruitments: +- Each -1 represents a crime. +- Each positive number represents the number of police officers recruited. +When a crime occurs and there are no available officers, it goes untreated. +Find the total number of untreated crimes. + +Example: +Input: + 7 + -1 -1 1 1 -1 -1 1 + +Output: + 2 + +Approach: +1. Traverse through the list of events. +2. Maintain a count of active police officers. +3. If a crime occurs and no officer is available, increase the untreated crimes count. +4. Otherwise, assign one available officer to handle the crime. + +Time Complexity: O(n) +Space Complexity: O(1) + +Contributor: Paila-Sahitya + +*/ + +#include +using namespace std; + +int policeRecruits(int n, vector &arr){ + int crimeCount=0; + int activePolice=0; + for(int i=0;i>n; + vector arr(n); + for(int i=0;i>arr[i]; + } + cout< sum of remaining coins. +3. Return the number of coins picked. + +Time Complexity: O(n log n) +Space Complexity: O(1) + +Contributor: Paila-Sahitya +*/ + +#include +using namespace std; + +int minimumCoins(int n, vector&arr){ + sort(arr.begin(), arr.end(), greater()); + int total=0; + for(int i=0;itotal-sum) return count; + } + return count; +} + +int main(){ + int n; + cin>>n; + vector arr(n); + for(int i=0;i>arr[i]; + } + cout<