Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stack>
- #include <math.h>
- #include <iostream>
- #include <algorithm>
- #include <string.h>
- #include <string>
- #include <set>
- #include <memory.h>
- #include <vector>
- #include <map>
- #include <queue>
- #include <iomanip>
- #include <ctime>
- #include <cassert>
- #define forn(i, n) for (int i = 0; i < int(n); i++)
- #define ll long long
- #define mp(a, b) make_pair(a, b)
- #define sqr(x) ( (x) * (x) )
- #define all(a) a.begin(), a.end()
- using namespace std;
- typedef pair <int, int> pt;
- typedef long double ld;
- const int INF = 1e9;
- const ld EPS = 1e-9;
- int a[101];
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int t, m;
- cin >> t >> m;
- int id = 1;
- forn (i, t) {
- string s;
- int x;
- cin >> s;
- if (s == "alloc") {
- cin >> x;
- bool ok = true;
- if (x > m) {
- cout << "NULL" << endl;
- continue;
- }
- forn (j, m - x + 1) {
- ok = true;
- for (int k = j; k < j + x && ok; k++) {
- if (a[k] != 0)
- ok = false;
- }
- if (ok) {
- for (int k = j; k < j + x && ok; k++) {
- a[k] = id;
- }
- cout << id << endl;
- id++;
- break;
- }
- }
- if (!ok)
- cout << "NULL" << endl;
- }
- if (s == "erase") {
- cin >> x;
- if (x < 1) {
- cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
- continue;
- }
- bool ok = false;
- forn (j, m) {
- if (a[j] == x) {
- a[j] = 0;
- ok = true;
- }
- }
- if (!ok) {
- cout << "ILLEGAL_ERASE_ARGUMENT" << endl;
- }
- }
- if (s == "defragment") {
- forn (j, m) {
- int k = j;
- while (k != 0 && a[k] != 0 && a[k - 1] == 0) {
- a[k - 1] = a[k];
- a[k] = 0;
- k--;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement