Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<int> solution(vector<int> memory, vector<vector<int>> query)
- {
- vector<int> ans(query.size());
- vector<int> allocate(memory.size(), 0);
- int id = 1;
- for (int i = 0; i < query.size(); i++)
- {
- int x = query[i][0];
- if (x == 0)
- {
- int len = query[i][1];
- bool f = false;
- for (int j = 0; j < memory.size(); j += 8)
- {
- int ct = 0;
- for (int k = j; k < memory.size(); k++)
- {
- if (memory[k] == 1)
- break;
- else
- ct++;
- if (ct >= len)
- break;
- }
- if (ct >= len)
- {
- ans.push_back(j);
- for (int k = j; k < len + j; k++)
- {
- allocate[k] = id;
- }
- id++;
- f = true;
- break;
- }
- }
- if (f == false)
- {
- ans.push_back(-1);
- }
- }
- else
- {
- int req_id;
- int ct = 0;
- for (int j = 0; j < memory.size(); j++)
- {
- if (memory[j] == req_id)
- {
- memory[j] = 0;
- ct++;
- }
- }
- if (ct == 0)
- ans.push_back(-1);
- else
- ans.push_back(ct);
- }
- }
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement