Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Minimum Amount of Time to Collect Garbage #348

Merged
merged 1 commit into from
Nov 20, 2023
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';
}();
Loading