diff --git a/Minimum Amount of Time to Collect Garbage b/Minimum Amount of Time to Collect Garbage new file mode 100644 index 0000000..29a73b9 --- /dev/null +++ b/Minimum Amount of Time to Collect Garbage @@ -0,0 +1,29 @@ +class Solution { +public: + int garbageCollection(vector& garbage, vector& 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'; +}();