Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions 2391. Minimum Amount of Time to Collect Garbage
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma GCC optimize("O3")
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';
}();