From 4a023f5f65aa9465553d54e8274c88e6ac2bd019 Mon Sep 17 00:00:00 2001 From: Jagpreet Singh Khurana <119691733+Jagpreet153@users.noreply.github.com> Date: Wed, 10 Apr 2024 23:37:13 +0530 Subject: [PATCH] feat: solved day 17 medium --- hard/day_17/solution.cpp | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/hard/day_17/solution.cpp b/hard/day_17/solution.cpp index 8d3ad8d..e8bedc8 100644 --- a/hard/day_17/solution.cpp +++ b/hard/day_17/solution.cpp @@ -1 +1,35 @@ -//write your code here \ No newline at end of file +//write your code here +// Code by Jagpreet153 +#include +using namespace std; +int main(){ + int t; + cin>>t; + while(t--){ + int n,m; + cin>>n>>m; + int a[m],d[m]; + for(int i=0;i>a[i]; + sort(a,a+m); + for(int i=0;i0) ans+=d[m-1-i]; //This is done to simulate the process of protecting the houses. If the resulting distance is greater than zero, it is added to the total number of houses that will be infected in the end + if(d[m-1-i]==0 && j==0) //If the resulting distance is zero and no house has been protected yet (j == 0), one house is protected and added to ans. + { + ans++; + j++; + } + } + cout<