Skip to content

Commit

Permalink
Create Minimum Amount of Time to Collect Garbage
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Nov 20, 2023
1 parent 66e0bb9 commit 3befcdc
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Minimum Amount of Time to Collect Garbage
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution {
public:
int garbageCollection(vector<string>& garbage, vector<int>& travel)
{
int n=garbage.size();
int tG=0, tP=0, tM=0;
int time=0;
#pragma unroll
for(int i=n-1; i>=0; i--){//time for collecting garbage
string x=garbage[i];
time+=x.size();
if (tG==0 && x.find('G')!=-1) tG=i;
if (tP==0 && x.find('P')!=-1) tP=i;
if (tM==0 && x.find('M')!=-1) tM=i;
}
// Add travel time
time+=accumulate(travel.begin(), travel.begin()+(tG),0)
+accumulate(travel.begin(), travel.begin()+(tP),0)
+accumulate(travel.begin(), travel.begin()+(tM),0);
return time;
}
};
auto init = []()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
return 'c';
}();

0 comments on commit 3befcdc

Please sign in to comment.