Created
August 9, 2024 07:17
-
-
Save rishabhgargg/7f6e11990d23935d2e80f98917d07a3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <unordered_map> | |
#include <string> | |
using namespace std; | |
int main() { | |
int n, k, m; | |
cin >> n >> k >> m; | |
vector<string> customers(n); | |
for (int i = 0; i < n; i++) { | |
cin >> customers[i]; | |
} | |
vector<string> requests(k); | |
for (int i = 0; i < k; i++) { | |
cin >> requests[i]; | |
} | |
unordered_map<string, int> lastServed; // To track the last week a customer was served | |
int weeks = 0; | |
for (int i = 0; i < k; i++) { | |
weeks++; // Start a new week for every request | |
if (lastServed.find(requests[i]) != lastServed.end()) { | |
int lastWeek = lastServed[requests[i]]; | |
if (weeks <= lastWeek + m) { | |
weeks = lastWeek + m + 1; | |
} | |
} | |
lastServed[requests[i]] = weeks; | |
} | |
cout << weeks << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment