From a607295878856ccd8fa6d036ffc301c849d53b96 Mon Sep 17 00:00:00 2001 From: Paila-Sahitya <233878361+Paila-Sahitya@users.noreply.github.com> Date: Thu, 23 Oct 2025 07:54:49 +0530 Subject: [PATCH 1/2] Added codeforces 160A --- .../Programs/C++/Twins.cpp | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Domains/CompetitiveProgramming/Programs/C++/Twins.cpp diff --git a/Domains/CompetitiveProgramming/Programs/C++/Twins.cpp b/Domains/CompetitiveProgramming/Programs/C++/Twins.cpp new file mode 100644 index 00000000..9336dc67 --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/C++/Twins.cpp @@ -0,0 +1,60 @@ +/* +Problem: Twins +Platform: Codeforces +Problem Code: 160A +Difficulty: Easy +Link: https://codeforces.com/problemset/problem/160/A + +Problem Statement: +Two brothers have a collection of coins of different values. +The goal is to find the minimum number of coins one brother must take +so that the total value of his coins becomes strictly greater than the +total value of the remaining coins. + +Example: +Input: + 4 + 3 3 4 3 +Output: + 2 + +Approach: +1. Sort the coins in descending order. +2. Keep picking the largest coins until the sum of selected coins > 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< Date: Thu, 23 Oct 2025 10:52:35 +0530 Subject: [PATCH 2/2] Added codeforces 427A --- .../Programs/C++/PoliceRecruits.cpp | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Domains/CompetitiveProgramming/Programs/C++/PoliceRecruits.cpp 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<